Skip to content

error: expected initializer before ‘<’ token #3907

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

Open
1 of 2 tasks
RerikOp opened this issue Jan 4, 2023 · 3 comments
Open
1 of 2 tasks

error: expected initializer before ‘<’ token #3907

RerikOp opened this issue Jan 4, 2023 · 3 comments

Comments

@RerikOp
Copy link

RerikOp commented Jan 4, 2023

Description

When using the single include header (https://github.com/nlohmann/json/blob/develop/single_include/nlohmann/json.hpp) I get the following error during compilation
error: expected initializer before ‘<’ token
in line 5323.
Sorry if it's an easy fix, I don't have much experience with C++.
I'm using g++ together with the latest CUDA compiler nvcc under WSL.
Edit: does not work using C++20, C++17 (probably below as well) compiles flawlessly

Reproduction steps

Include "json.hpp" in any header file

Expected vs. actual results

Expected: Successful compilation
Actual: No compilation

Minimal code example

No response

Error messages

No response

Compiler and operating system

g++ (Ubuntu 12.1.0-2ubuntu1~22.04) 12.1.0 | Cuda compilation tools, release 12.0, V12.0.76 Build cuda_12.0.r12.0/compiler.31968024_0

Library version

version 3.11.2

Validation

@ghost
Copy link

ghost commented Jan 28, 2023

Can confirm the bug for

  • Ubuntu 22.04
  • g++12
  • cuda 12
  • CMake 3.25.2
build-debug/_deps/json-src/include/nlohmann/detail/iterators/iteration_proxy.hpp:241:22: error: expected initializer before ‘<’ token
  241 |     inline constexpr bool ::std::ranges::enable_borrowed_range<::nlohmann::detail::iteration_proxy<IteratorType>> = true;

No error when the library is compiled with c++17

@shaoyaoqian
Copy link

shaoyaoqian commented Nov 28, 2023

Same error. You might compile the program with nvcc as the default compiler. I have the same problem but can't find the solution. I used the 3.8.0 to avoid this problem.

@steef435
Copy link

Looking at this, it seems that support for ranges (a C++20 feature) is disabled on g++11. I have the issue above with nvcc12 and g++10.2.1. Maybe there should be more checks here? (I thought nvcc just used gcc's headers, so maybe it has nothing to do with CUDA/nvcc.)

In any case, I wanted to share the workaround of disabling ranges with

#define JSON_HAS_RANGES 0

before including the library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants