This is an archive of the discontinued LLVM Phabricator instance.

[Modules TS] Diagnose exported internal linkage declarations
Needs ReviewPublic

Authored by hamzasood on Dec 24 2017, 10:45 AM.

Details

Reviewers
rsmith
boris
bruno
Summary

Diagnose attempts to export declarations with internal linkage, as mentioned in [dcl.module.interface]p2 in the Modules TS.

I would've liked to add a FixIt hint to remove the static keyword if present, but I couldn't work out how to get the SourceRange that covers it (it's accessible from the Declarator, but seemingly not after the actual node has been created).
I've left a fixme comment in there in case anyone else can figure it out.

Diff Detail

Event Timeline

hamzasood created this revision.Dec 24 2017, 10:45 AM

I've removed the isExported fix for namespaces as it's somewhat unrelated to this patch.
I'll do a separate patch for fixing namespaces (which will include the stuff removed from here and a bit more)

rsmith added inline comments.Apr 27 2018, 4:52 PM
include/clang/AST/DeclBase.h
2055–2075

Neat :)

lib/Sema/SemaDecl.cpp
16354

This will prematurely stop traversal if we reach a LinkageSpecDecl. I think we should instead stop if we reach a declaration for which !DC->getRedeclContext()->isFileContext() (that is, we should check namespace-scope declarations only).

  • Fixed the premature loop termination issue pointed out by @rsmith (and added a test case for it).
  • Fixed a few small issues regarding diagnosing exported enum/struct/union declarations without a name (especially anonymous unions at namespace-scope).
  • Factored out the loop body into a separate function to keep things tidy.
hamzasood marked an inline comment as done.Jul 21 2018, 11:39 AM
bruno resigned from this revision.Nov 9 2020, 12:33 PM