[clang] [C++20] [Modules] Warn for duplicated decls in mutliple module units (PR #105799)

Mikael Holmén via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 23 03:34:49 PDT 2024


================
@@ -9955,6 +9955,45 @@ void ASTReader::finishPendingActions() {
   }
   PendingDefinitions.clear();
 
+  for (auto [D, Previous] : PendingWarningForDuplicatedDefsInModuleUnits) {
+    auto hasDefinitionImpl = [this](Decl *D, auto hasDefinitionImpl) {
+      if (auto *VD = dyn_cast<VarDecl>(D))
+        return VD->isThisDeclarationADefinition() ||
+               VD->isThisDeclarationADemotedDefinition();
+
+      if (auto *TD = dyn_cast<TagDecl>(D))
+        return TD->isThisDeclarationADefinition() ||
+               TD->isThisDeclarationADemotedDefinition();
+
+      if (auto *FD = dyn_cast<FunctionDecl>(D))
+        return FD->isThisDeclarationADefinition() || PendingBodies.count(FD);
+
+      if (auto *RTD = dyn_cast<RedeclarableTemplateDecl>(D))
+        return hasDefinitionImpl(RTD->getTemplatedDecl(), hasDefinitionImpl);
+
+      // Conservatively return false here.
+      return false;
+    };
+
+    auto hasDefinition = [this, &hasDefinitionImpl](Decl *D) {
----------------
mikaelholmen wrote:

I get a clang warning here:
```
../../clang/lib/Serialization/ASTReader.cpp:9978:27: error: lambda capture 'this' is not used [-Werror,-Wunused-lambda-capture]
    auto hasDefinition = [this, &hasDefinitionImpl](Decl *D) {
                          ^~~~~
1 error generated.
```

https://github.com/llvm/llvm-project/pull/105799


More information about the cfe-commits mailing list