r246014 - [Sema] Don't assume CallExpr::getDirectCallee will succeed

David Majnemer via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 25 22:13:19 PDT 2015


Author: majnemer
Date: Wed Aug 26 00:13:19 2015
New Revision: 246014

URL: http://llvm.org/viewvc/llvm-project?rev=246014&view=rev
Log:
[Sema] Don't assume CallExpr::getDirectCallee will succeed

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.

Modified:
    cfe/trunk/lib/Sema/SemaExpr.cpp
    cfe/trunk/test/SemaCXX/err_typecheck_assign_const.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=246014&r1=246013&r2=246014&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Wed Aug 26 00:13:19 2015
@@ -9316,7 +9316,7 @@ static void DiagnoseConstAssignment(Sema
   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;

Modified: cfe/trunk/test/SemaCXX/err_typecheck_assign_const.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/err_typecheck_assign_const.cpp?rev=246014&r1=246013&r2=246014&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/err_typecheck_assign_const.cpp (original)
+++ cfe/trunk/test/SemaCXX/err_typecheck_assign_const.cpp Wed Aug 26 00:13:19 2015
@@ -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}}
+}




More information about the cfe-commits mailing list