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

E2500 error in C++20 build (MSVC) format.h line 2748 (fmt v8.0.1) #2552

Closed
cliffdiamond opened this issue Oct 18, 2021 · 4 comments
Closed

Comments

@cliffdiamond
Copy link

cliffdiamond commented Oct 18, 2021

This could be minor but the more I read up about it, the more it's looking like there's an issue here. Maybe you can code around it.

I'm getting an Intellisense-only error in format.h at line 2748 when building with VS2022. It seems to relate to the use of fixed_string in the template parameters.

The full error is:

E2500 a literal operator template must have a template parameter list equivalent to '<char ...>'

I'm using fmt V8.0.1 with headers only (FMT_HEADER_ONLY), with my language standard option set to /std:c++20. I've also tried /std:c++latest but the problem persists. It disappears when switching to /std:c++17.

I found this article (https://stackoverflow.com/questions/53789050/template-parameter-list-for-literal-operator) which seems to relate to the issue but may be out-of-date as it's a couple of years old. It seems to be saying that gcc is wrong in allowing non-char parameters, and quotes the following in the C++ standard (though it doesn't say which version of the standard):

"The declaration of a literal operator template shall have an empty parameter-declaration-clause and its template-parameter-list shall have a single template-parameter that is a non-type template parameter pack with element type char."

Please advise if this is something that should be changed to be more compliant.

Regards

Cliff

@cliffdiamond cliffdiamond changed the title E2500 error in C++20 build (MSVC) format.h line 2748 (v8.0.1) E2500 error in C++20 build (MSVC) format.h line 2748 (fmt v8.0.1) Oct 18, 2021
@alexezeder
Copy link
Contributor

It's actually string literal operator template and it works thanks to C++20 non-type template parameter, without any GCC or Clang extensions.

Looks like there is the same issue - #2536.

@cliffdiamond
Copy link
Author

I've reported this to the VS developers.

@lifeinaglasshouse
Copy link

lifeinaglasshouse commented Jan 6, 2023

This bug still happen after a year. It seem like Microsoft still didn't fix it. I cannot find any other solution other than changing to C++17

Hope this issue could be solved.

@mpayrits
Copy link

Still no change with Visual Studio 17.5.0, but this can be worked around by defining FMT_USE_NONTYPE_TEMPLATE_ARGS=0 on the cl.exe command line or just before including fmt headers. We managed to continue using fmt in MSVC with C++20 this way without further issues.
Note: this applies to fmt v9.x. For v8.x (and possibly earlier), the macro name is different and one has to define FMT_USE_NONTYPE_TEMPLATE_PARAMETERS=0.
Note 2: our use case involves CUDA and to get that to work with newer versions of nvcc and MSVC with C++20 and fmt v9.x, we also had to define FMT_USE_CONSTEXPR=1. v8.x works without that extra define and it's probably not necessary for straight C++ either.

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

5 participants