Bug 104091 - -std=c++20 causing meaningless error message "'auto' not allowed in alias declaration" which should be "missing template arguments after ..."
Summary: -std=c++20 causing meaningless error message "'auto' not allowed in alias dec...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 12.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
: 101221 (view as bug list)
Depends on:
Blocks:
 
Reported: 2022-01-18 11:00 UTC by qingzhe huang
Modified: 2022-11-07 09:55 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2022-11-07 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description qingzhe huang 2022-01-18 11:00:14 UTC
considering following snippet of code:

template<typename T, template<typename...>typename Template>
struct Specialization{};
template<template<typename...>typename Template, typename...Args>
struct Specialization<Template<Args...>, Template>{
    using type=Template;
};


Using -std=c++20 gives meaningless error message of "'auto' not allowed in alias declaration". While -std=c++17 or before all give correct error message:
"missing template arguments after 'Template<...auto...>'". And -std=c++14 is even better with "invalid use of template-name 'Template' without an argument list".

See https://godbolt.org/z/Wb9nKzcPT
Comment 1 Andrew Pinski 2022-01-18 11:10:11 UTC
Confirmed reduced to just:
template<typename> class Tt;
using type=Tt;
Comment 2 Jonathan Wakely 2022-11-07 09:49:28 UTC
I've just hit this myself and was quite confused by the diagnostic.

A realistic but still close to minimal reproducer is:

namespace x
{
  template<class T> struct S { };
}

struct A
{
  using S = ::x::S;
};


Unsurprisingly, you get the same error with -std=c++17 -fconcepts, because the compiler seems to be treating the template-id as a placeholder-type-specifier, maybe even as a type-constraint. Neither makes sense as the defining-type-id of an alias-declaration.


With -std=c++14 you get a correct "invalid use of template-name" error, but then an incorrect note about CTAD:

using.cc:8:13: error: invalid use of template-name 'x::S' without an argument list
    8 |   using S = ::x::S;
      |             ^~
using.cc:8:13: note: class template argument deduction is only available with '-std=c++17' or '-std=gnu++17'
using.cc:3:28: note: 'template<class T> struct x::S' declared here
    3 |   template<class T> struct S { };
      |                            ^

Although it's true that CTAD isn't available in C++14, it's not relevant here because it couldn't be used here anyway (as evidenced by the fact it still doesn't compie in C++17).


I would expect the same error for C++14 and C++17 (and ideally C++20 too) since the code is invalid in exactly the same way in all cases. C++17 gives a similar error to C++14 but with slightly different wording for some reason:

using.cc:8:13: error: missing template arguments after 'x::S'
    8 |   using S = ::x::S;
      |             ^~
      |               <>
using.cc:3:28: note: 'template<class T> struct x::S' declared here
    3 |   template<class T> struct S { };
      |                            ^


So we should:

1) fix the bogus "auto not allowed" when concepts are enabled;
2) harmonize the C++14 and C++17 wording about missing template args;
3) remove the bogus note about CTAD.
Comment 3 Jonathan Wakely 2022-11-07 09:53:14 UTC
*** Bug 101221 has been marked as a duplicate of this bug. ***
Comment 4 Jonathan Wakely 2022-11-07 09:55:50 UTC
A slight variation from PR 101221:

template<class T> struct S;
template<class T> using SS = S;


For comparison, Clang and EDG give exactly the same diagnostic for all examples above irrespective of C++14/17/20 mode.