-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[clang][Diagnostic] Clarify error message for auto #149781
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
Open
jdoe3945
wants to merge
10
commits into
llvm:main
Choose a base branch
from
jdoe3945:personal/edror/issue_147324_missing_location_auto
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
90ae570
[clang][Diagnostic] Clarify error message for auto
jdoe3945 39d3fd5
Merge branch 'main' into personal/edror/issue_147324_missing_location…
jdoe3945 76dc7f2
[clang][Diagnostic] Clarify error message for auto
jdoe3945 76f5dfd
Merge remote-tracking branch 'upstream/main' into personal/edror/issu…
jdoe3945 1784182
Merge branch 'main' into personal/edror/issue_147324_missing_location…
jdoe3945 5f46b44
Merge remote-tracking branch 'origin/main' into personal/edror/issue_…
jdoe3945 bcafa33
Merge remote-tracking branch 'upstream/main' into personal/edror/issu…
jdoe3945 3a37a99
Add testing for the example in the issue
jdoe3945 809acc2
Adhere to style rules
jdoe3945 07a1200
Merge branch 'main' into personal/edror/issue_147324_missing_location…
jdoe3945 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8454,24 +8454,37 @@ Sema::CheckTemplateDeclScope(Scope *S, TemplateParameterList *TemplateParams) { | |
| // C++ [temp.class.spec]p6: [P2096] | ||
| // A partial specialization may be declared in any scope in which the | ||
| // corresponding primary template may be defined. | ||
| auto FindTemplateParamsLoc = [](TemplateParameterList *TemplateParams, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please move the declaration so that the comment above and the corresponding code are not separated. |
||
| SourceLocation Fallback) { | ||
| SourceLocation DiagLoc = TemplateParams->getTemplateLoc(); | ||
| if (DiagLoc.isValid()) | ||
| return DiagLoc; | ||
|
|
||
| for (const NamedDecl *Param : *TemplateParams) | ||
| if (Param && Param->getLocation().isValid()) | ||
| return Param->getLocation(); | ||
|
|
||
| return Fallback; | ||
| }; | ||
|
|
||
| if (Ctx) { | ||
| if (Ctx->isFileContext()) | ||
| return false; | ||
| if (CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(Ctx)) { | ||
| // C++ [temp.mem]p2: | ||
| // A local class shall not have member templates. | ||
| if (RD->isLocalClass()) | ||
| return Diag(TemplateParams->getTemplateLoc(), | ||
| return Diag(FindTemplateParamsLoc(TemplateParams, RD->getLocation()), | ||
| diag::err_template_inside_local_class) | ||
| << TemplateParams->getSourceRange(); | ||
| else | ||
| return false; | ||
| << TemplateParams->getSourceRange(); | ||
|
|
||
| return false; | ||
| } | ||
| } | ||
|
|
||
| return Diag(TemplateParams->getTemplateLoc(), | ||
| return Diag(FindTemplateParamsLoc(TemplateParams, SourceLocation()), | ||
| diag::err_template_outside_namespace_or_class_scope) | ||
| << TemplateParams->getSourceRange(); | ||
| << TemplateParams->getSourceRange(); | ||
| } | ||
|
|
||
| /// Determine what kind of template specialization the given declaration | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| // RUN: %clang_cc1 %std_cxx98-14 -fsyntax-only -verify=expected,precxx17 %s | ||
| // RUN: %clang_cc1 %std_cxx17- -fsyntax-only -verify=expected,cxx17 %s | ||
|
|
||
| // Check that 'auto' in a local class function parameter | ||
| // produces the correct diagnostic depending on the language standard: | ||
| // * Before C++17 → "'auto' not allowed in function prototype" | ||
| // * C++17 and later → "templates cannot be declared inside of a local class" | ||
|
|
||
| int main() { | ||
| struct A { | ||
| void foo(auto x) {} // precxx17-error {{'auto' not allowed in function prototype}} \ | ||
| // cxx17-error {{templates cannot be declared inside of a local class}} | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // RUN: %clang_cc1 -fsyntax-only -verify %s | ||
|
|
||
| void foo() { | ||
| struct Local { | ||
| template <typename T> // expected-error {{member templates are not allowed inside local classes}} | ||
jdoe3945 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| void bar(); | ||
| }; | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please reference the issue fixed by this patch like other entries.