aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-05-23 19:43:23 +0000
committerDouglas Gregor <dgregor@apple.com>2010-05-23 19:43:23 +0000
commit9ba6af8bedba28d10a6906c62c19d43f81c5d386 (patch)
treece6ec330d3add11515ebd07fc441ab262211e1bc
parent928e6fcf66fc4f342bcf7cc96bf56986c9c2a833 (diff)
Complain about sizeof(overloaded function) rather than crashing.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@104470 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/DiagnosticSemaKinds.td3
-rw-r--r--lib/Sema/SemaExpr.cpp6
-rw-r--r--test/SemaCXX/alignof-sizeof-reference.cpp6
3 files changed, 15 insertions, 0 deletions
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index 6f98b65eda..5b7b0c566c 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1870,6 +1870,9 @@ def err_func_def_incomplete_result : Error<
// Expressions.
def ext_sizeof_function_type : Extension<
"invalid application of 'sizeof' to a function type">, InGroup<PointerArith>;
+def err_sizeof_alignof_overloaded_function_type : Error<
+ "invalid application of '%select{sizeof|__alignof}0' to an overloaded "
+ "function">;
def ext_sizeof_void_type : Extension<
"invalid application of '%0' to a void type">, InGroup<PointerArith>;
def err_sizeof_alignof_incomplete_type : Error<
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 0c150ffeed..5e2e732572 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -2027,6 +2027,12 @@ bool Sema::CheckSizeOfAlignOfOperand(QualType exprType,
return true;
}
+ if (Context.hasSameUnqualifiedType(exprType, Context.OverloadTy)) {
+ Diag(OpLoc, diag::err_sizeof_alignof_overloaded_function_type)
+ << !isSizeof << ExprRange;
+ return true;
+ }
+
return false;
}
diff --git a/test/SemaCXX/alignof-sizeof-reference.cpp b/test/SemaCXX/alignof-sizeof-reference.cpp
index f02282d72d..dd64d6a23a 100644
--- a/test/SemaCXX/alignof-sizeof-reference.cpp
+++ b/test/SemaCXX/alignof-sizeof-reference.cpp
@@ -7,3 +7,9 @@ void test() {
static_assert(alignof(r) == 1, "bad alignment");
static_assert(sizeof(r) == 1, "bad size");
}
+
+void f();
+void f(int);
+void g() {
+ sizeof(&f); // expected-error{{invalid application of 'sizeof' to an overloaded function}}
+}