Skip to content

clang: Missing line and file in message error when ‘auto’ is used in a not permitted context (and bad diagnostic) #147324

Open
@jonathanpoelen

Description

@jonathanpoelen

With this code:

int main()
{ 
  struct A
  { 
    void foo(auto x) {} // auto not permitted
  };
} 

And clang-18,19,20 or trunk and -std=c++20 or -std=c++23:

error: templates cannot be declared inside of a local class

No line number, no filename and refer to template.

With -std=c++17:

test.cpp:5:14: error: 'auto' not allowed in function prototype
    5 |     void foo(auto x) {}
      |              ^~~~

With gcc (same message for C++17 or C++20):

test.cpp: In function ‘int main()’:
test.cpp:5:14: error: ‘auto’ parameter not permitted in this context
    5 |     void foo(auto x) {}
      |              ^~~~

https://gcc.godbolt.org/z/5YGdh6Pnb

Metadata

Metadata

Assignees

Labels

clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerconfirmedVerified by a second partygood first issuehttps://github.com/llvm/llvm-project/contribute

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions