-
-
Notifications
You must be signed in to change notification settings - Fork 7.2k
Open
Labels
Description
Description
(Yes, I have read #3827, #4038, #4039 and #4205)
The original compiler error in #3827 is because in a template context, the compiler (GCC) cannot infer that the type of value
is const nlohmann::json &
, thus .template get
is needed.
However, this seems to be a bug of GCC, because key
is extracted from sourceData.items()
, and sourceData
is not dependent on template variables K
or V
.
I suggest to remove most of the template
keyword when not required i.e. not in a template context, as suggested in #4205, because:
.template get
is unnecessary in a non-template context. See the code in #3827 but whenconvert
is a regular function, this compiled with gcc 12.4 without error.- GCC fixed this in 13.1. The original code (https://godbolt.org/z/Gxv7dbsjW) compiles correctly with the latest GCC.
- Excessive use of
.template get
in the documentation makes the code too verbose, and might recommend the users to use theget_to
API, which separates the definition and initiation and is not ideal.
Reproduction steps
Ran some tests in compiler explorer:
- The original code, won't compile with GCC 12.4. link
- The original code, compiles correctly with GCC 13.1. link
- The original code but
convert
is converted into a regular function, compiles without error in GCC 12.4. link
Expected vs. actual results
Should remove the template
keywords not in actual template definitions.
Minimal code example
Error messages
Compiler and operating system
GCC 12.4 and GCC 13.1
Library version
develop branch
Validation
- The bug also occurs if the latest version from the
develop
branch is used. - I can successfully compile and run the unit tests.