r216369 - [modules] Fix false report of an ODR violation when merging friend

Richard Smith richard-llvm at metafoo.co.uk
Sun Aug 24 19:10:02 PDT 2014


Author: rsmith
Date: Sun Aug 24 21:10:01 2014
New Revision: 216369

URL: http://llvm.org/viewvc/llvm-project?rev=216369&view=rev
Log:
[modules] Fix false report of an ODR violation when merging friend
declarations. We can't expect to find them in the canonical definition
of the class, because that's not where they live.

This means we no longer reject real ODR violations with friend declarations,
but we weren't consistently doing so anyway.

Modified:
    cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
    cfe/trunk/test/Modules/Inputs/odr/a.h
    cfe/trunk/test/Modules/Inputs/odr/b.h
    cfe/trunk/test/Modules/odr.cpp

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=216369&r1=216368&r2=216369&view=diff
==============================================================================
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Sun Aug 24 21:10:01 2014
@@ -2548,7 +2548,9 @@ ASTDeclReader::FindExistingResult ASTDec
   //
   // FIXME: We should do something similar if we merge two definitions of the
   // same template specialization into the same CXXRecordDecl.
-  if (Reader.MergedDeclContexts.count(D->getLexicalDeclContext()))
+  auto MergedDCIt = Reader.MergedDeclContexts.find(D->getLexicalDeclContext());
+  if (MergedDCIt != Reader.MergedDeclContexts.end() &&
+      MergedDCIt->second == D->getDeclContext())
     Reader.PendingOdrMergeChecks.push_back(D);
 
   return FindExistingResult(Reader, D, /*Existing=*/nullptr);

Modified: cfe/trunk/test/Modules/Inputs/odr/a.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/odr/a.h?rev=216369&r1=216368&r2=216369&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/odr/a.h (original)
+++ cfe/trunk/test/Modules/Inputs/odr/a.h Sun Aug 24 21:10:01 2014
@@ -8,6 +8,12 @@ struct X {
   int n;
 } x1;
 
+template<typename T>
+struct F {
+  int n;
+  friend bool operator==(const F &a, const F &b) { return a.n == b.n; }
+};
+
 int f() {
   return y1.n + e1 + y1.f + x1.n;
 }

Modified: cfe/trunk/test/Modules/Inputs/odr/b.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/odr/b.h?rev=216369&r1=216368&r2=216369&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/odr/b.h (original)
+++ cfe/trunk/test/Modules/Inputs/odr/b.h Sun Aug 24 21:10:01 2014
@@ -4,6 +4,12 @@ struct Y {
 } y2;
 enum E { e2 };
 
+template<typename T>
+struct F {
+  int n;
+  friend bool operator==(const F &a, const F &b) { return a.n == b.n; }
+};
+
 int g() {
-  return y2.m + e2 + y2.f;
+  return y2.m + e2 + y2.f + (F<int>{0} == F<int>{1});
 }

Modified: cfe/trunk/test/Modules/odr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/odr.cpp?rev=216369&r1=216368&r2=216369&view=diff
==============================================================================
--- cfe/trunk/test/Modules/odr.cpp (original)
+++ cfe/trunk/test/Modules/odr.cpp Sun Aug 24 21:10:01 2014
@@ -6,6 +6,9 @@ struct X { // expected-note {{definition
 };
 
 @import a;
+
+bool b = F<int>{0} == F<int>{1};
+
 @import b;
 
 // Trigger the declarations from a and b to be imported.





More information about the cfe-commits mailing list