This testcase uses the name of a non-static member function as a
truthvalue, which is ill-formed and confuses
c_common_truthvalue_conversion. Avoid the ICE by explicitly comparing
it to nullptr, which will get the "invalid use of member function" error
we want.
Tested x86_64-pc-linux-gnu, applying to trunk and 4.8.
commit 44c3240b029ab9f7bfb2a1a64245ea8ef3af9a49
Author: Jason Merrill <ja...@redhat.com>
Date: Mon Jan 27 10:11:11 2014 -0500
PR c++/58837
* typeck.c (cp_truthvalue_conversion): Use explicit comparison for
FUNCTION_DECL.
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 78090a7..b7ece1b 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -5182,7 +5182,9 @@ tree
cp_truthvalue_conversion (tree expr)
{
tree type = TREE_TYPE (expr);
- if (TYPE_PTRDATAMEM_P (type))
+ if (TYPE_PTRDATAMEM_P (type)
+ /* Avoid ICE on invalid use of non-static member function. */
+ || TREE_CODE (expr) == FUNCTION_DECL)
return build_binary_op (EXPR_LOCATION (expr),
NE_EXPR, expr, nullptr_node, 1);
else if (TYPE_PTR_P (type) || TYPE_PTRMEMFUNC_P (type))
diff --git a/gcc/testsuite/g++.dg/cpp0x/static_assert9.C b/gcc/testsuite/g++.dg/cpp0x/static_assert9.C
new file mode 100644
index 0000000..fccaa44
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/static_assert9.C
@@ -0,0 +1,7 @@
+// PR c++/58837
+// { dg-require-effective-target c++11 }
+
+void f();
+static_assert(f, "");
+struct A {};
+static_assert(A::~A, ""); // { dg-error "non-static member function" }