]> granicus.if.org Git - clang/commitdiff
[Sema] Don't assume CallExpr::getDirectCallee will succeed
authorDavid Majnemer <david.majnemer@gmail.com>
Wed, 26 Aug 2015 05:13:19 +0000 (05:13 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Wed, 26 Aug 2015 05:13:19 +0000 (05:13 +0000)
We tried to provide a very nice diagnostic when diagnosing an assignment
to a const int & produced by a function call.  However, we cannot always
determine what function was called.

This fixes PR24568.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@246014 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExpr.cpp
test/SemaCXX/err_typecheck_assign_const.cpp

index f2c0fb82eefddcd45b670c2ab34048b52457945a..5297d7e26a4547520ab74ecee664a7d628ce03fb 100644 (file)
@@ -9316,7 +9316,7 @@ static void DiagnoseConstAssignment(Sema &S, const Expr *E,
   if (const CallExpr *CE = dyn_cast<CallExpr>(E)) {
     // Function calls
     const FunctionDecl *FD = CE->getDirectCallee();
-    if (!IsTypeModifiable(FD->getReturnType(), IsDereference)) {
+    if (FD && !IsTypeModifiable(FD->getReturnType(), IsDereference)) {
       if (!DiagnosticEmitted) {
         S.Diag(Loc, diag::err_typecheck_assign_const) << ExprRange
                                                       << ConstFunction << FD;
index 376b6e6491591b54e083f3e48f372f2fd21760d8..7e2812565144e93e7ee2e7b41af129ad7ec8e000 100644 (file)
@@ -122,3 +122,10 @@ void test12(H h) {
   h.a = 1;  // expected-error {{cannot assign to non-static data member 'a' with const-qualified type 'const int'}}
   h.b = 2;  // expected-error {{cannot assign to non-static data member 'b' with const-qualified type 'const int &'}}
 }
+
+void test() {
+  typedef const int &Func();
+
+  Func &bar();
+  bar()() = 0; // expected-error {{read-only variable is not assignable}}
+}