Change assertion to quick exit from checking function.
authorRichard Trieu <rtrieu@google.com>
Wed, 1 Nov 2017 03:57:27 +0000 (03:57 +0000)
committerRichard Trieu <rtrieu@google.com>
Wed, 1 Nov 2017 03:57:27 +0000 (03:57 +0000)
Remove the assertion that could be triggered by invalid code.  Replace it with
an early exit from the checking function.

llvm-svn: 317073

clang/lib/Sema/SemaDeclCXX.cpp
clang/test/SemaCXX/missing-members.cpp

index fa9e9f3..a5ccce6 100644 (file)
@@ -2555,9 +2555,8 @@ Sema::CheckDerivedToBaseConversion(QualType Derived, QualType Base,
   CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true,
                      /*DetectVirtual=*/false);
   bool DerivationOkay = IsDerivedFrom(Loc, Derived, Base, Paths);
-  assert(DerivationOkay &&
-         "Can only be used with a derived-to-base conversion");
-  (void)DerivationOkay;
+  if (!DerivationOkay)
+    return true;
 
   const CXXBasePath *Path = nullptr;
   if (!Paths.isAmbiguous(Context.getCanonicalType(Base).getUnqualifiedType()))
index 96bed07..61dddcb 100644 (file)
@@ -37,3 +37,17 @@ struct S : A::B::C {
   using A::B::C::f; // expected-error {{no member named 'f' in 'A::B::C'}}
   
 };
+
+struct S1 {};
+
+struct S2 : S1 {};
+
+struct S3 : S2 {
+  void run();
+};
+
+struct S4: S3 {};
+
+void test(S4 *ptr) {
+  ptr->S1::run();  // expected-error {{no member named 'run' in 'S1'}}
+}