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

Diagnostics for template keywords showing up inside local classes aren't good #17959

Closed
majnemer mannequin opened this issue Oct 15, 2013 · 2 comments · Fixed by #99933
Closed

Diagnostics for template keywords showing up inside local classes aren't good #17959

majnemer mannequin opened this issue Oct 15, 2013 · 2 comments · Fixed by #99933
Labels
bugzilla Issues migrated from bugzilla clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer

Comments

@majnemer
Copy link
Mannequin

majnemer mannequin commented Oct 15, 2013

Bugzilla Link 17585
Version unspecified
OS Linux
CC @DougGregor,@zygoloid

Extended Description

consider:

void foo() {
  template <typename> int i;
}

we issue:

error: expected expression

gcc provides a better error:

error: a template declaration cannot appear at block scope

another case:

void foo() {
  struct S { template <typename> int i; };
}

we issue:

error: member 'i' declared as a template

gcc provides:

invalid declaration of member template in local class

These plain english messages are very nice, we should do something similar.

@zygoloid
Copy link
Mannequin

zygoloid mannequin commented Oct 15, 2013

void foo() {
struct S { template int i; };
}

we issue:

error: member 'i' declared as a template

This diagnostic is bad in the non-local-class case too. Something like

non-static data member 'i' cannot be declared as a template

would be better, to suggest that maybe the 'static' keyword is missing.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 9, 2021
@shafik shafik added clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer clang:frontend Language frontend issues, e.g. anything involving "Sema" and removed c++ labels Jul 22, 2024
@llvmbot
Copy link
Member

llvmbot commented Jul 22, 2024

@llvm/issue-subscribers-clang-frontend

Author: None (991901f3-cc14-4404-b340-165691b62a58)

| | | | --- | --- | | Bugzilla Link | [17585](https://llvm.org/bz17585) | | Version | unspecified | | OS | Linux | | CC | @DougGregor,@zygoloid |

Extended Description

consider:

void foo() {
  template &lt;typename&gt; int i;
}

we issue:

error: expected expression

gcc provides a better error:

error: a template declaration cannot appear at block scope

another case:

void foo() {
  struct S { template &lt;typename&gt; int i; };
}

we issue:

error: member 'i' declared as a template

gcc provides:

invalid declaration of member template in local class

These plain english messages are very nice, we should do something similar.

@EugeneZelenko EugeneZelenko removed the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Jul 22, 2024
sgundapa pushed a commit to sgundapa/upstream_effort that referenced this issue Jul 23, 2024
It turns out `SemaTemplate` handles this type of diagnostic already,
however when template gets encountered, it never gets parsed as a
possible statement or declaration, only as an expression.

Fixes llvm#17959.
yuxuanchen1997 pushed a commit that referenced this issue Jul 25, 2024
It turns out `SemaTemplate` handles this type of diagnostic already,
however when template gets encountered, it never gets parsed as a
possible statement or declaration, only as an expression.

Fixes #17959.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla clang:diagnostics New/improved warning or error message in Clang, but not in clang-tidy or static analyzer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants