https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106354

            Bug ID: 106354
           Summary: Diagnostic could be more user friendly
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: barry.revzin at gmail dot com
  Target Milestone: ---

Consider:

template <typename T>
constexpr bool some_check() {
    return true;
}

struct C { };

static_assert(some_check<C>::value);

This is (obviously) wrong: some_check is a function template, not a type trait,
so the correct way to validate it is some_check<C>() and not
some_check<C>::value. But there's a lot of code uses type traits, so this sort
of thing happens.

gcc 12 tells me:

<source>:8:15: error: function template-id 'some_check<C>' in
nested-name-specifier
    8 | static_assert(some_check<C>::value);
      |               ^~~~~~~~~~~~~
<source>:2:16: note: 'template<class T> constexpr bool some_check()' declared
here
    2 | constexpr bool some_check() {
      |                ^~~~~~~~~~

Now, technically, this is all... correct. You can't use a function template-id
in a nested-name-specifier, and the error does point me to the declaration of
the function template in question which helped me realize my error. 

But it'd be nice to provide this error in less grammatical terms (especially
since the problem here was that I didn't realize some_check was a function
template). Maybe something like:

error: can only access nested names on class types or namespaces, but
some_check is a function template.

This can probably be improved further.
  • [Bug c++/106354] New: Diagnosti... barry.revzin at gmail dot com via Gcc-bugs

Reply via email to