summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/Sema/SemaExpr.cpp2
-rw-r--r--clang/test/SemaCXX/err_typecheck_assign_const.cpp7
2 files changed, 8 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index f2c0fb82eef..5297d7e26a4 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -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;
diff --git a/clang/test/SemaCXX/err_typecheck_assign_const.cpp b/clang/test/SemaCXX/err_typecheck_assign_const.cpp
index 376b6e64915..7e281256514 100644
--- a/clang/test/SemaCXX/err_typecheck_assign_const.cpp
+++ b/clang/test/SemaCXX/err_typecheck_assign_const.cpp
@@ -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}}
+}
OpenPOWER on IntegriCloud