Repository navigation
[clang][Modules] Complete the implementation of P2615: Meaningful exports #194201
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
localspook
wants to merge
13
commits into
llvm:main
Choose a base branch
from
localspook:meaningful-exports
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 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
b8f38d5
[clang][Modules] Complete the implementation of P2615: Meaningful exp…
localspook b2e7ab4
Add fix-it tests
localspook fc4e1c3
Allow linkage-specification on partial specializations
localspook 012415d
Add workaround for MSVC STL
localspook a6d6b28
Adjust text of error message; address nits in tests
localspook c8bee39
Mark CWG2443 as resolved and add tests
localspook 95c6d00
Address feedback in DR test
localspook ac5f826
Factor out some reusable functions
localspook 8270a02
Undo assert
localspook a4c37e4
Remove trailing whitespace
localspook 376bad9
Change from error to warning
localspook 8464a81
Add check for `-fms-extensions`
localspook b94cd84
Add warning groups
localspook 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
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 |
|---|---|---|
|
|
@@ -339,9 +339,11 @@ Decl *Parser::ParseLinkage(ParsingDeclSpec &DS, DeclaratorContext Context) { | |
| // ... but anyway remember that such an "extern" was seen. | ||
| DS.setExternInLinkageSpec(true); | ||
| ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs, &DS); | ||
| return LinkageSpec ? Actions.ActOnFinishLinkageSpecification( | ||
| getCurScope(), LinkageSpec, SourceLocation()) | ||
| : nullptr; | ||
| if (!LinkageSpec) | ||
| return nullptr; | ||
| CheckUnbracedLinkageOrExportDeclaration(LinkageSpec); | ||
| return Actions.ActOnFinishLinkageSpecification(getCurScope(), LinkageSpec, | ||
| SourceLocation()); | ||
| } | ||
|
|
||
| DS.abort(); | ||
|
|
@@ -420,6 +422,7 @@ Decl *Parser::ParseExportDeclaration() { | |
| MaybeParseCXX11Attributes(DeclAttrs); | ||
| ParsedAttributes EmptyDeclSpecAttrs(AttrFactory); | ||
| ParseExternalDeclaration(DeclAttrs, EmptyDeclSpecAttrs); | ||
| CheckUnbracedLinkageOrExportDeclaration(ExportDecl); | ||
| return Actions.ActOnFinishExportDecl(getCurScope(), ExportDecl, | ||
| SourceLocation()); | ||
| } | ||
|
|
@@ -440,6 +443,52 @@ Decl *Parser::ParseExportDeclaration() { | |
| T.getCloseLocation()); | ||
| } | ||
|
|
||
| void Parser::CheckUnbracedLinkageOrExportDeclaration( | ||
| Decl *LinkageOrExportDecl) { | ||
| const auto *DC = cast<DeclContext>(LinkageOrExportDecl); | ||
| if (DC->decls_empty()) | ||
| return; | ||
|
Comment on lines
+449
to
+450
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. I don't think that can ever be true, we should assert on it instead
Member
Author
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. That causes the following tests to fail: |
||
|
|
||
| const Decl *D = *DC->decls_begin(); | ||
|
|
||
| // Nested export declarations are diagnosed elsewhere. | ||
| if (isa<LinkageSpecDecl>(LinkageOrExportDecl) && isa<ExportDecl>(D)) { | ||
| Diag(LinkageOrExportDecl->getLocation(), | ||
| diag::err_invalid_decl_in_linkage_spec) | ||
| << 2; | ||
|
localspook marked this conversation as resolved.
Outdated
|
||
| return; | ||
| } | ||
|
|
||
| TemplateSpecializationKind TSK = [&] { | ||
|
localspook marked this conversation as resolved.
Outdated
|
||
| if (const auto *EID = dyn_cast<ExplicitInstantiationDecl>(D)) | ||
| return EID->getTemplateSpecializationKind(); | ||
| if (const auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(D)) | ||
| return CTSD->getTemplateSpecializationKind(); | ||
| if (const auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(D)) | ||
| return VTSD->getTemplateSpecializationKind(); | ||
| if (const auto *FD = dyn_cast<FunctionDecl>(D)) | ||
| return FD->getTemplateSpecializationKind(); | ||
| return TSK_Undeclared; | ||
| }(); | ||
|
localspook marked this conversation as resolved.
Outdated
|
||
|
|
||
| if (TSK == TSK_Undeclared) | ||
| return; | ||
|
|
||
| if (const auto *ED = dyn_cast<ExportDecl>(LinkageOrExportDecl)) { | ||
| Diag(ED->getExportLoc(), diag::err_meaningless_export) | ||
| << (TSK == TSK_ExplicitSpecialization) | ||
| << FixItHint::CreateRemoval(ED->getExportLoc()); | ||
|
localspook marked this conversation as resolved.
|
||
| Diag(ED->getExportLoc(), diag::note_meaningless_export_explanation); | ||
| return; | ||
| } | ||
|
|
||
| if (const auto *LS = dyn_cast<LinkageSpecDecl>(LinkageOrExportDecl)) { | ||
| Diag(LS->getLocation(), diag::err_invalid_decl_in_linkage_spec) | ||
| << (TSK == TSK_ExplicitSpecialization); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| Parser::DeclGroupPtrTy Parser::ParseUsingDirectiveOrDeclaration( | ||
| DeclaratorContext Context, const ParsedTemplateInfo &TemplateInfo, | ||
| SourceLocation &DeclEnd, ParsedAttributes &Attrs) { | ||
|
|
||
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 |
|---|---|---|
|
|
@@ -55,7 +55,7 @@ extern "C++" { | |
| int h(); | ||
| } | ||
|
|
||
| extern "C++" export int g(); | ||
| export int g(); | ||
|
|
||
| //--- d.cpp | ||
| import c; | ||
|
|
||
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
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
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 |
|---|---|---|
|
|
@@ -42,7 +42,7 @@ export template <typename T> | |
| void foo4() { | ||
| } | ||
|
|
||
| export template <> | ||
| template <> | ||
| void foo4<int>() { | ||
| } | ||
|
|
||
|
|
||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.