r230115 - Improve diagnostic when failing to synthesize implicit member due to dllexport (PR22591)

Hans Wennborg hans at hanshq.net
Fri Feb 20 17:07:24 PST 2015


Author: hans
Date: Fri Feb 20 19:07:24 2015
New Revision: 230115

URL: http://llvm.org/viewvc/llvm-project?rev=230115&view=rev
Log:
Improve diagnostic when failing to synthesize implicit member due to dllexport (PR22591)

This is only a problem in C++03 mode targeting MS ABI (MinGW doesn't
export inline methods, and C++11 marks these methods implicitly
deleted).

Since targeting the MS ABI in pre-C++11 mode is a rare configuration,
this will probably not get fixed, but we can at least have a better
error message.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp
    cfe/trunk/test/SemaCXX/dllexport-pr22591.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=230115&r1=230114&r2=230115&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Feb 20 19:07:24 2015
@@ -1302,6 +1302,8 @@ def err_missing_default_ctor : Error<
   "%select{|implicit default |inheriting }0constructor for %1 must explicitly "
   "initialize the %select{base class|member}2 %3 which does not have a default "
   "constructor">;
+def note_due_to_dllexported_class : Note<
+  "due to '%0' being dllexported%select{|; try compiling in C++11 mode}1">;
 
 def err_illegal_union_or_anon_struct_member : Error<
   "%select{anonymous struct|union}0 member %1 has a non-trivial "

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=230115&r1=230114&r2=230115&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Fri Feb 20 19:07:24 2015
@@ -4821,7 +4821,13 @@ static void checkDLLAttribute(Sema &S, C
         // defaulted methods, and the copy and move assignment operators. The
         // latter are exported even if they are trivial, because the address of
         // an operator can be taken and should compare equal accross libraries.
+        DiagnosticErrorTrap Trap(S.Diags);
         S.MarkFunctionReferenced(Class->getLocation(), MD);
+        if (Trap.hasErrorOccurred()) {
+          S.Diag(ClassAttr->getLocation(), diag::note_due_to_dllexported_class)
+              << Class->getName() << !S.getLangOpts().CPlusPlus11;
+          break;
+        }
 
         // There is no later point when we will see the definition of this
         // function, so pass it to the consumer now.

Modified: cfe/trunk/test/SemaCXX/dllexport-pr22591.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/dllexport-pr22591.cpp?rev=230115&r1=230114&r2=230115&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/dllexport-pr22591.cpp (original)
+++ cfe/trunk/test/SemaCXX/dllexport-pr22591.cpp Fri Feb 20 19:07:24 2015
@@ -1,16 +1,25 @@
 // RUN: %clang_cc1 -triple i686-windows-gnu  -verify -std=c++03 %s
 // RUN: %clang_cc1 -triple i686-windows-gnu  -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple i686-windows-msvc -verify -std=c++03 -DERROR %s
 // RUN: %clang_cc1 -triple i686-windows-msvc -verify -std=c++11 %s
 
-// FIXME: For C++03 MS ABI we erroneously try to synthesize default ctor, etc. for S.
-
+#ifndef ERROR
 // expected-no-diagnostics
+#endif
 
 struct NonCopyable {
 private:
+#ifdef ERROR
+  // expected-note at +2{{declared private here}}
+#endif
   NonCopyable();
 };
 
+#ifdef ERROR
+// expected-error at +4{{field of type 'NonCopyable' has private default constructor}}
+// expected-note at +3{{implicit default constructor for 'S' first required here}}
+// expected-note at +2{{due to 'S' being dllexported; try compiling in C++11 mode}}
+#endif
 struct __declspec(dllexport) S {
   NonCopyable member;
 };





More information about the cfe-commits mailing list