Skip to content

README.md and documentation overuse template keyword before get function #4823

@AlexGuo1998

Description

@AlexGuo1998

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:

  1. .template get is unnecessary in a non-template context. See the code in #3827 but when convert is a regular function, this compiled with gcc 12.4 without error.
  2. GCC fixed this in 13.1. The original code (https://godbolt.org/z/Gxv7dbsjW) compiles correctly with the latest GCC.
  3. Excessive use of .template get in the documentation makes the code too verbose, and might recommend the users to use the get_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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions