[PATCH] D140261: [C++20][Modules] Do not allow non-inline external definitions in header units.

Iain Sandoe via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 19 04:31:59 PST 2022


iains marked 2 inline comments as done.
iains added a comment.

OK so this is what I plan to land assuming testing goes OK.
I suspect that this might cause some user code to flag errors - there are quite a number of ODR violations "in the wild".



================
Comment at: clang/lib/Sema/SemaDecl.cpp:12957-12958
+  // units.
+  if (getLangOpts().CPlusPlus20 && getLangOpts().CPlusPlusModules &&
+      !ModuleScopes.empty() && ModuleScopes.back().Module->isHeaderUnit()) {
+    if (VDecl->getFormalLinkage() == Linkage::ExternalLinkage &&
----------------
ChuanqiXu wrote:
> iains wrote:
> > ChuanqiXu wrote:
> > > `getLangOpts().CPlusPlus20` is redundant. It is also good to define a helper interface `withinHeaderUnit` in Sema (not required).
> > I do not mind making this change - but note that the constraint is specific to C++20 and there are some people who want to remove it (the constraint).  I guess  you meant `getCurrentModule()` ?
> > I do not mind making this change - but note that the constraint is specific to C++20 and there are some people who want to remove it (the constraint).
> 
> Got it. Let's make it when it comes true. It won't be a big deal.
> 
> > I guess you meant getCurrentModule() ?
> 
> It looks **a little bit** better to me to not access `ModuleScopes` directly.
revised now (I added the helper).



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D140261/new/

https://reviews.llvm.org/D140261



More information about the cfe-commits mailing list