Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"call to non-‘constexpr’ function" in bundled fmt #2142

Closed
limitedAtonement opened this issue Oct 17, 2021 · 9 comments
Closed

"call to non-‘constexpr’ function" in bundled fmt #2142

limitedAtonement opened this issue Oct 17, 2021 · 9 comments

Comments

@limitedAtonement
Copy link

Here is an incomplete example that reproduces the problem:

#include "spdlog/spdlog.h"
std::shared_ptr<spdlog::logger> logger;
int main(int, char const **)
{
    std::string m{"{:06d}"};
    logger->info(m, 1);
    return 0;
}

I'm working against eb322062 (tag: v1.9.2) Bump version to 1.9.2 (and I was able to reproduce on 8826011c (origin/v1.x, v1.x) Merge pull request #2102 from yzz-ihep/v1.x). Invocation:

#!/bin/bash

set -ex;
g++ --version;
if [[ ! -d obj ]]; then mkdir obj; fi;
g++ -c -Wall -Wextra -pedantic -std=c++20 -O3 -DNDEBUG -MMD -Isrc/spdlog/include src/main.cpp -o obj/main.o;

The full output:

+ g++ --version
g++ (GCC) 11.1.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

+ [[ ! -d obj ]]
+ g++ -c -Wall -Wextra -pedantic -std=c++20 -O3 -DNDEBUG -MMD -Isrc/spdlog/include src/main.cpp -o obj/main.o
In file included from src/spdlog/include/spdlog/fmt/fmt.h:22,
                 from src/spdlog/include/spdlog/common.h:36,
                 from src/spdlog/include/spdlog/spdlog.h:12,
                 from src/main.cpp:1:
src/spdlog/include/spdlog/fmt/bundled/core.h: In function ‘int main(int, const char**)’:
src/main.cpp:6:17:   in ‘constexpr’ expansion of ‘fmt::v8::basic_format_string<char, int>(m)’
src/spdlog/include/spdlog/fmt/bundled/core.h:2835:51: error: ‘constexpr fmt::v8::basic_string_view<Char>::basic_string_view(const std::__cxx11::basic_string<Char, Traits, Alloc>&) [with Traits = std::char_traits<char>; Alloc = std::allocator<char>; Char = char]’ called in a constant expression
 2835 |   FMT_CONSTEVAL basic_format_string(const S& s) : str_(s) {
      |                                                   ^~~~~~~
src/spdlog/include/spdlog/fmt/bundled/core.h:470:17: note: ‘constexpr fmt::v8::basic_string_view<Char>::basic_string_view(const std::__cxx11::basic_string<Char, Traits, Alloc>&) [with Traits = std::char_traits<char>; Alloc = std::allocator<char>; Char = char]’ is not usable as a ‘constexpr’ function because:
  470 |   FMT_CONSTEXPR basic_string_view(
      |                 ^~~~~~~~~~~~~~~~~
src/spdlog/include/spdlog/fmt/bundled/core.h:472:21: error: call to non-‘constexpr’ function ‘const _CharT* std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::data() const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’
  472 |       : data_(s.data()),
      |               ~~~~~~^~
In file included from /usr/include/c++/11.1.0/string:55,
                 from /usr/include/c++/11.1.0/stdexcept:39,
                 from /usr/include/c++/11.1.0/system_error:41,
                 from /usr/include/c++/11.1.0/bits/std_mutex.h:39,
                 from /usr/include/c++/11.1.0/bits/atomic_wait.h:49,
                 from /usr/include/c++/11.1.0/bits/atomic_base.h:41,
                 from /usr/include/c++/11.1.0/atomic:41,
                 from src/spdlog/include/spdlog/details/null_mutex.h:6,
                 from src/spdlog/include/spdlog/common.h:7,
                 from src/spdlog/include/spdlog/spdlog.h:12,
                 from src/main.cpp:1:
/usr/include/c++/11.1.0/bits/basic_string.h:2318:7: note: ‘const _CharT* std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::data() const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>]’ declared here
 2318 |       data() const _GLIBCXX_NOEXCEPT
      |       ^~~~

(which shows that the gcc version is 11.1.0 and compile flags include -Wall -Wextra -pedantic -std=c++20 -O3 -DNDEBUG -MMD).

This seems related maybe to #2023 except I'm not mixing format expression types? Maybe a relative of #1811?

@tt4g
Copy link
Contributor

tt4g commented Oct 17, 2021

Related this issue: fmtlib/fmt#2455

@gabime
Copy link
Owner

gabime commented Oct 17, 2021

fixed in fmt

@gabime gabime closed this as completed Oct 17, 2021
@limitedAtonement
Copy link
Author

Thank you! Which version of spdlog should contain this fix (so that the example above works)?

@gabime
Copy link
Owner

gabime commented Oct 18, 2021

In the next release of spdlog version (no date yet)

Edit: probably after next fmt release with this fix.

@Brainfridge
Copy link

Is this fix out yet? I am seeing this in the compiled library in spdlog code I got today.

@iripiri
Copy link

iripiri commented Feb 22, 2023

I have the same issue, cloned spdlog today

@Kelvin-Ng
Copy link

I have the same issue on 1.12.0, but it works fine on 1.11.0.

junaire added a commit to junaire/solidity that referenced this issue Aug 24, 2023
In our downstream project, we have two dependencies: solidity and spdlog.
Both of them depend on fmtlib. Unfortunately, the versions of fmtlib they
use do not match, which leads to compilation failure.

The issue arises because spdlog attempts to use solidity's fmtlib, but the
specific version (v8.0.1) has a bug. Ref: gabime/spdlog#2142

While we could keep this change in our own fork, we believe it would
be worthwhile to contribute it back to the upstream since spdlog is a
very popular logging library.

Signed-off-by: Jun Zhang <[email protected]>
junaire added a commit to junaire/solidity that referenced this issue Aug 24, 2023
In our downstream project, we have two dependencies: solidity and spdlog.
Both of them depend on fmtlib. Unfortunately, the versions of fmtlib they
use do not match, which leads to compilation failure.

The issue arises because spdlog attempts to use solidity's fmtlib, but the
specific version (v8.0.1) has a bug. Ref: gabime/spdlog#2142

While we could keep this change in our own fork, we believe it would
be worthwhile to contribute it back to the upstream since spdlog is a
very popular logging library.

Signed-off-by: Jun Zhang <[email protected]>
junaire added a commit to junaire/solidity that referenced this issue Aug 28, 2023
In our downstream project, we have two dependencies: solidity and spdlog.
Both of them depend on fmtlib. Unfortunately, the versions of fmtlib they
use do not match, which leads to compilation failure.

The issue arises because spdlog attempts to use solidity's fmtlib, but the
specific version (v8.0.1) has a bug. Ref: gabime/spdlog#2142

While we could keep this change in our own fork, we believe it would
be worthwhile to contribute it back to the upstream since spdlog is a
very popular logging library.

Signed-off-by: Jun Zhang <[email protected]>
@sammyj85
Copy link

sammyj85 commented Sep 22, 2023

It would seem this bug issue should be reopened. I also echo "I have the same issue on 1.12.0, but it works fine on 1.11.0."

Somewhere between Nov 2 2022 (1.11.0) and Feb 9 2023 it broke again.

@gabime
Copy link
Owner

gabime commented Sep 22, 2023

@sammyj85 Can you try the v2.x branch? I hope it solves this.

Ruko97 pushed a commit to Ruko97/solidity that referenced this issue Apr 7, 2024
In our downstream project, we have two dependencies: solidity and spdlog.
Both of them depend on fmtlib. Unfortunately, the versions of fmtlib they
use do not match, which leads to compilation failure.

The issue arises because spdlog attempts to use solidity's fmtlib, but the
specific version (v8.0.1) has a bug. Ref: gabime/spdlog#2142

While we could keep this change in our own fork, we believe it would
be worthwhile to contribute it back to the upstream since spdlog is a
very popular logging library.

Signed-off-by: Jun Zhang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants