Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[clang] Improve error message for template at block scope #99892

Closed
chrchr-github opened this issue Jul 22, 2024 · 3 comments
Closed

[clang] Improve error message for template at block scope #99892

chrchr-github opened this issue Jul 22, 2024 · 3 comments
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer duplicate Resolved as duplicate

Comments

@chrchr-github
Copy link

int main() {
    template<typename T>
    struct S{};
}

clang:

<source>:2:5: error: expected expression
    2 |     template<typename T>
      |     ^

gcc:

<source>:2:5: error: a template declaration cannot appear at block scope
    2 |     template<typename T>
      |     ^~~~~~~~

msvc:

<source>(2): error C2951: template declarations are only permitted at global, namespace, or class scope
<source>(2): error C3857: 'S': multiple template parameter lists are not allowed

https://godbolt.org/z/5cGvn68xv

@github-actions github-actions bot added the clang Clang issues not falling into any other category label Jul 22, 2024
@shafik shafik added clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer and removed clang Clang issues not falling into any other category labels Jul 22, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 22, 2024

@llvm/issue-subscribers-clang-frontend

Author: None (chrchr-github)

~~~c++ int main() { template<typename T> struct S{}; } ~~~ clang: ~~~ <source>:2:5: error: expected expression 2 | template<typename T> | ^ ~~~ gcc: ~~~ <source>:2:5: error: a template declaration cannot appear at block scope 2 | template<typename T> | ^~~~~~~~ ~~~ msvc: ~~~ <source>(2): error C2951: template declarations are only permitted at global, namespace, or class scope <source>(2): error C3857: 'S': multiple template parameter lists are not allowed ~~~ https://godbolt.org/z/5cGvn68xv

@shafik
Copy link
Collaborator

shafik commented Jul 22, 2024

Yeah, that is not super helpful diagnostic.

@shafik
Copy link
Collaborator

shafik commented Jul 22, 2024

duplicate: #17959

@shafik shafik closed this as not planned Won't fix, can't repro, duplicate, stale Jul 22, 2024
@EugeneZelenko EugeneZelenko added duplicate Resolved as duplicate and removed clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer duplicate Resolved as duplicate
Projects
None yet
Development

No branches or pull requests

4 participants