r185056 - Fix a conversion to incomplete type bug -- The error message now specifically states that the type is incomplete and points to the forward declaration of the incomplete type.

Larisse Voufo lvoufo at google.com
Wed Jun 26 18:50:25 PDT 2013


Author: lvoufo
Date: Wed Jun 26 20:50:25 2013
New Revision: 185056

URL: http://llvm.org/viewvc/llvm-project?rev=185056&view=rev
Log:
Fix a conversion to incomplete type bug -- The error message now specifically states that the type is incomplete and points to the forward declaration of the incomplete type.

Added:
    cfe/trunk/test/SemaCXX/conversion-incomplete-type.cpp
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaInit.cpp
    cfe/trunk/lib/Sema/SemaOverload.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=185056&r1=185055&r2=185056&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Jun 26 20:50:25 2013
@@ -5014,6 +5014,8 @@ def err_typecheck_ambiguous_condition :
   "conversion %diff{from $ to $|between types}0,1 is ambiguous">;
 def err_typecheck_nonviable_condition : Error<
   "no viable conversion%diff{ from $ to $|}0,1">;
+def err_typecheck_nonviable_condition_incomplete : Error<
+  "no viable conversion%diff{ from $ to incomplete type $|}0,1">;
 def err_typecheck_deleted_function : Error<
   "conversion function %diff{from $ to $|between types}0,1 "
   "invokes a deleted function">;

Modified: cfe/trunk/lib/Sema/SemaInit.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaInit.cpp?rev=185056&r1=185055&r2=185056&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaInit.cpp (original)
+++ cfe/trunk/lib/Sema/SemaInit.cpp Wed Jun 26 20:50:25 2013
@@ -6251,9 +6251,15 @@ bool InitializationSequence::Diagnose(Se
       break;
 
     case OR_No_Viable_Function:
-      S.Diag(Kind.getLocation(), diag::err_typecheck_nonviable_condition)
-        << Args[0]->getType() << DestType.getNonReferenceType()
-        << Args[0]->getSourceRange();
+      if (!DestType.getNonReferenceType()->isIncompleteType() ||
+          !S.RequireCompleteType(Kind.getLocation(),
+                                 DestType.getNonReferenceType(),
+                          diag::err_typecheck_nonviable_condition_incomplete,
+                               Args[0]->getType(), Args[0]->getSourceRange()))
+        S.Diag(Kind.getLocation(), diag::err_typecheck_nonviable_condition)
+          << Args[0]->getType() << Args[0]->getSourceRange()
+          << DestType.getNonReferenceType();
+
       FailedCandidateSet.NoteCandidates(S, OCD_AllCandidates, Args);
       break;
 

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=185056&r1=185055&r2=185056&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Wed Jun 26 20:50:25 2013
@@ -3231,10 +3231,15 @@ Sema::DiagnoseMultipleUserDefinedConvers
     Diag(From->getLocStart(),
          diag::err_typecheck_ambiguous_condition)
           << From->getType() << ToType << From->getSourceRange();
-  else if (OvResult == OR_No_Viable_Function && !CandidateSet.empty())
-    Diag(From->getLocStart(),
-         diag::err_typecheck_nonviable_condition)
-    << From->getType() << ToType << From->getSourceRange();
+  else if (OvResult == OR_No_Viable_Function && !CandidateSet.empty()) {
+    if (!ToType->isIncompleteType() ||
+        !RequireCompleteType(From->getLocStart(), ToType,
+                          diag::err_typecheck_nonviable_condition_incomplete,
+                             From->getType(), From->getSourceRange()))
+      Diag(From->getLocStart(),
+           diag::err_typecheck_nonviable_condition)
+           << From->getType() << From->getSourceRange() << ToType;
+  }
   else
     return false;
   CandidateSet.NoteCandidates(*this, OCD_AllCandidates, From);

Added: cfe/trunk/test/SemaCXX/conversion-incomplete-type.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/conversion-incomplete-type.cpp?rev=185056&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/conversion-incomplete-type.cpp (added)
+++ cfe/trunk/test/SemaCXX/conversion-incomplete-type.cpp Wed Jun 26 20:50:25 2013
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+struct string {};
+
+class StringPiece;  // expected-note {{forward declaration of 'StringPiece'}} \
+                    // expected-note {{forward declaration of 'StringPiece'}}
+
+struct Test {
+  void expectStringPiece(const StringPiece& blah) {};  // expected-note {{passing argument to parameter 'blah' here}}
+  
+  void test(const string& s) { 
+    expectStringPiece(s);  // expected-error {{no viable conversion from 'const string' to incomplete type 'const StringPiece'}}
+  }
+};
+
+struct TestStatic {
+  static void expectStringPiece(const StringPiece& blah) {};  // expected-note {{passing argument to parameter 'blah' here}}
+  
+  static void test(const string& s) { 
+    expectStringPiece(s);  // expected-error {{no viable conversion from 'const string' to incomplete type 'const StringPiece'}}
+  }
+};
+





More information about the cfe-commits mailing list