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

compiler error using clang-16.0.5 when using gcc-13.1 standard library #4051

Closed
2 tasks
janwilmans opened this issue Jun 9, 2023 · 5 comments
Closed
2 tasks
Labels
kind: bug state: please discuss please discuss the issue or vote for your favorite option

Comments

@janwilmans
Copy link

Description

https://godbolt.org/z/jnxMe6veT

workaround: -DJSON_HAS_RANGES=0

Reproduction steps

na.

Expected vs. actual results

no compilation error vs. compilation error

Minimal code example

#include <nlohmann/json.hpp>
#include <sstream>
#include <iomanip>

using nlohmann::json;

int main()
{
    std::stringstream ss;
    json j = {"foo", 1, 2, 3, false, {{"one", 1}}};
    ss << std::setw(1) << std::setfill('\t') << j;

}

Error messages

In file included from <source>:1:
In file included from /opt/compiler-explorer/libs/nlohmann_json/trunk/single_include/nlohmann/json.hpp:5097:
/opt/compiler-explorer/gcc-13.1.0/lib/gcc/x86_64-linux-gnu/13.1.0/../../../../include/c++/13.1.0/ranges:6151:14: error: requires clause differs in template redeclaration
    requires forward_range<_Vp>
             ^
/opt/compiler-explorer/gcc-13.1.0/lib/gcc/x86_64-linux-gnu/13.1.0/../../../../include/c++/13.1.0/ranges:5850:14: note: previous template declaration is here
    requires input_range<_Vp>
             ^
/opt/compiler-explorer/gcc-13.1.0/lib/gcc/x86_64-linux-gnu/13.1.0/../../../../include/c++/13.1.0/ranges:8846:20: error: type-id cannot have a name
    { return (auto(__x) += __y); }
                   ^
/opt/compiler-explorer/gcc-13.1.0/lib/gcc/x86_64-linux-gnu/13.1.0/../../../../include/c++/13.1.0/ranges:8846:25: error: expected ')'
    { return (auto(__x) += __y); }
                        ^
/opt/compiler-explorer/gcc-13.1.0/lib/gcc/x86_64-linux-gnu/13.1.0/../../../../include/c++/13.1.0/ranges:8846:14: note: to match this '('
    { return (auto(__x) += __y); }
             ^
/opt/compiler-explorer/gcc-13.1.0/lib/gcc/x86_64-linux-gnu/13.1.0/../../../../include/c++/13.1.0/ranges:8846:32: error: expected expression
    { return (auto(__x) += __y); }
                               ^
4 errors generated.
ASM generation compiler returned: 1
In file included from <source>:1:
In file included from /opt/compiler-explorer/libs/nlohmann_json/trunk/single_include/nlohmann/json.hpp:5097:
/opt/compiler-explorer/gcc-13.1.0/lib/gcc/x86_64-linux-gnu/13.1.0/../../../../include/c++/13.1.0/ranges:6151:14: error: requires clause differs in template redeclaration
    requires forward_range<_Vp>
             ^
/opt/compiler-explorer/gcc-13.1.0/lib/gcc/x86_64-linux-gnu/13.1.0/../../../../include/c++/13.1.0/ranges:5850:14: note: previous template declaration is here
    requires input_range<_Vp>
             ^
/opt/compiler-explorer/gcc-13.1.0/lib/gcc/x86_64-linux-gnu/13.1.0/../../../../include/c++/13.1.0/ranges:8846:20: error: type-id cannot have a name
    { return (auto(__x) += __y); }
                   ^
/opt/compiler-explorer/gcc-13.1.0/lib/gcc/x86_64-linux-gnu/13.1.0/../../../../include/c++/13.1.0/ranges:8846:25: error: expected ')'
    { return (auto(__x) += __y); }
                        ^
/opt/compiler-explorer/gcc-13.1.0/lib/gcc/x86_64-linux-gnu/13.1.0/../../../../include/c++/13.1.0/ranges:8846:14: note: to match this '('
    { return (auto(__x) += __y); }
             ^
/opt/compiler-explorer/gcc-13.1.0/lib/gcc/x86_64-linux-gnu/13.1.0/../../../../include/c++/13.1.0/ranges:8846:32: error: expected expression
    { return (auto(__x) += __y); }
                               ^
4 errors generated.
Execution build compiler returned: 1

Compiler and operating system

Linux, clang-16.0.5+gcc-13.1 standard library

Library version

3.11.2

Validation

@nlohmann
Copy link
Owner

We use GCC 13.3.0 in the CI. Can you please re-test with the latest develop branch?

@nlohmann nlohmann added the state: needs more info the author of the issue needs to provide more details label Nov 29, 2024
@janwilmans
Copy link
Author

the problem persists, I think it is triggered by clang lacking support for some ranges feature.
see: https://godbolt.org/z/cbEK3s1W9, which tests clang 16 + gcc 13.3

image

@janwilmans
Copy link
Author

janwilmans commented Dec 2, 2024

The same setting for Clang 17.0.1 works
https://godbolt.org/z/fPocKaT5j

I think the ranges-detection asks the standard library 'what it supports', but then there is compiler support in clang-16 missing that the standard library from gcc 13.1 relies on. So maybe this this not a bug, but something that can't be reliably queried?

@nlohmann nlohmann removed the state: needs more info the author of the issue needs to provide more details label Dec 5, 2024
@nlohmann
Copy link
Owner

nlohmann commented Dec 5, 2024

Sorry, I missed the point about mixing Clang with GCC's STL. We do check Clang with both libc++ and libstdc++, but only for the latest Clang version (20.0.0). I'm not sure to what extend I can test all combinations of Clang/GCC.

With #4440 we have a similar issue with ranges.

Maybe we need to refine this detection code to incorporate the experiences from the compiler combinations. Apparently, it is insufficient to "trust" defined(__cpp_lib_ranges):

#ifndef JSON_HAS_RANGES
    // ranges header shipping in GCC 11.1.0 (released 2021-04-27) has syntax error
    #if defined(__GLIBCXX__) && __GLIBCXX__ == 20210427
        #define JSON_HAS_RANGES 0
    #elif defined(__cpp_lib_ranges)
        #define JSON_HAS_RANGES 1
    #else
        #define JSON_HAS_RANGES 0
    #endif
#endif

@nlohmann nlohmann added the state: please discuss please discuss the issue or vote for your favorite option label Dec 5, 2024
@janwilmans
Copy link
Author

janwilmans commented Dec 9, 2024

I did some more testing, it is indeed very specific for some combinations and I did not find a reliable way to detect this. Let's just close this as 'won't fix'

@janwilmans janwilmans closed this as not planned Won't fix, can't repro, duplicate, stale Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug state: please discuss please discuss the issue or vote for your favorite option
Projects
None yet
Development

No branches or pull requests

2 participants