aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPaolo Carlini <paolo@gcc.gnu.org>2016-05-31 17:17:29 +0000
committerPaolo Carlini <paolo@gcc.gnu.org>2016-05-31 17:17:29 +0000
commitc642d91957c82c4a1db50e17f62dc0aa70b8765e (patch)
tree14aab8875329d71e895c769273607c53e4fadfe1 /gcc
parent1ac1bb0cccdba65e0fc1c4f28e92d1fb2f593ac2 (diff)
downloadgcc-c642d91957c82c4a1db50e17f62dc0aa70b8765e.zip
gcc-c642d91957c82c4a1db50e17f62dc0aa70b8765e.tar.gz
gcc-c642d91957c82c4a1db50e17f62dc0aa70b8765e.tar.bz2
re PR c++/71248 (crash on in-class initializer of array of pointer to member)
/cp 2016-05-31 Paolo Carlini <paolo.carlini@oracle.com> PR c++/71248 * decl.c (check_static_variable_definition): Use DECL_SOURCE_LOCATION to obtain correct locations; avoid redundant diagnostics on out-of-class definitions. /testsuite 2016-05-31 Paolo Carlini <paolo.carlini@oracle.com> PR c++/71248 * g++.dg/cpp0x/pr71248.C: New. * g++.dg/cpp0x/auto7.C: Test column numbers too. * g++.dg/cpp0x/constexpr-static8.C: Likewise. * g++.dg/init/new37.C: Likewise. * g++.dg/template/static1.C: Likewise. * g++.dg/template/static2.C: Likewise. From-SVN: r236931
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog9
-rw-r--r--gcc/cp/decl.c32
-rw-r--r--gcc/testsuite/ChangeLog10
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/auto7.C2
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/constexpr-static8.C4
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/pr71248.C10
-rw-r--r--gcc/testsuite/g++.dg/init/new37.C3
-rw-r--r--gcc/testsuite/g++.dg/template/static1.C4
-rw-r--r--gcc/testsuite/g++.dg/template/static2.C4
9 files changed, 59 insertions, 19 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 266ca0a..0401255 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,4 +1,11 @@
-2016-05-27 Martin Sebor <msebor@redhat.com>
+2016-05-31 Paolo Carlini <paolo.carlini@oracle.com>
+
+ PR c++/71248
+ * decl.c (check_static_variable_definition): Use DECL_SOURCE_LOCATION
+ to obtain correct locations; avoid redundant diagnostics on
+ out-of-class definitions.
+
+2016-05-30 Martin Sebor <msebor@redhat.com>
PR c++/71306
* init.c (warn_placement_new_too_small): Handle placement new arguments
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index ef5fd66..cbbb84b 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -8581,6 +8581,9 @@ build_ptrmem_type (tree class_type, tree member_type)
static int
check_static_variable_definition (tree decl, tree type)
{
+ /* Avoid redundant diagnostics on out-of-class definitions. */
+ if (!current_class_type || !TYPE_BEING_DEFINED (current_class_type))
+ return 0;
/* Can't check yet if we don't know the type. */
if (dependent_type_p (type))
return 0;
@@ -8591,15 +8594,17 @@ check_static_variable_definition (tree decl, tree type)
else if (cxx_dialect >= cxx11 && !INTEGRAL_OR_ENUMERATION_TYPE_P (type))
{
if (!COMPLETE_TYPE_P (type))
- error ("in-class initialization of static data member %q#D of "
- "incomplete type", decl);
+ error_at (DECL_SOURCE_LOCATION (decl),
+ "in-class initialization of static data member %q#D of "
+ "incomplete type", decl);
else if (literal_type_p (type))
- permerror (input_location,
+ permerror (DECL_SOURCE_LOCATION (decl),
"%<constexpr%> needed for in-class initialization of "
"static data member %q#D of non-integral type", decl);
else
- error ("in-class initialization of static data member %q#D of "
- "non-literal type", decl);
+ error_at (DECL_SOURCE_LOCATION (decl),
+ "in-class initialization of static data member %q#D of "
+ "non-literal type", decl);
return 1;
}
@@ -8611,17 +8616,20 @@ check_static_variable_definition (tree decl, tree type)
required. */
if (!ARITHMETIC_TYPE_P (type) && TREE_CODE (type) != ENUMERAL_TYPE)
{
- error ("invalid in-class initialization of static data member "
- "of non-integral type %qT",
- type);
+ error_at (DECL_SOURCE_LOCATION (decl),
+ "invalid in-class initialization of static data member "
+ "of non-integral type %qT",
+ type);
return 1;
}
else if (!CP_TYPE_CONST_P (type))
- error ("ISO C++ forbids in-class initialization of non-const "
- "static member %qD",
- decl);
+ error_at (DECL_SOURCE_LOCATION (decl),
+ "ISO C++ forbids in-class initialization of non-const "
+ "static member %qD",
+ decl);
else if (!INTEGRAL_OR_ENUMERATION_TYPE_P (type))
- pedwarn (input_location, OPT_Wpedantic, "ISO C++ forbids initialization of member constant "
+ pedwarn (DECL_SOURCE_LOCATION (decl), OPT_Wpedantic,
+ "ISO C++ forbids initialization of member constant "
"%qD of non-integral type %qT", decl, type);
return 0;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 2cf6a94..cc1624f 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,13 @@
+2016-05-31 Paolo Carlini <paolo.carlini@oracle.com>
+
+ PR c++/71248
+ * g++.dg/cpp0x/pr71248.C: New.
+ * g++.dg/cpp0x/auto7.C: Test column numbers too.
+ * g++.dg/cpp0x/constexpr-static8.C: Likewise.
+ * g++.dg/init/new37.C: Likewise.
+ * g++.dg/template/static1.C: Likewise.
+ * g++.dg/template/static2.C: Likewise.
+
2016-05-31 H.J. Lu <hongjiu.lu@intel.com>
* gcc.target/i386/avx512vl-vbroadcast-3.c: Scan %\[re\]di
diff --git a/gcc/testsuite/g++.dg/cpp0x/auto7.C b/gcc/testsuite/g++.dg/cpp0x/auto7.C
index c213c74..99685d3 100644
--- a/gcc/testsuite/g++.dg/cpp0x/auto7.C
+++ b/gcc/testsuite/g++.dg/cpp0x/auto7.C
@@ -7,7 +7,7 @@ auto j; // { dg-error "has no initializer" }
template<int> struct A
{
- static auto k = 7; // { dg-error "non-const" }
+ static auto k = 7; // { dg-error "15:ISO C\\+\\+ forbids" }
static auto l; // { dg-error "has no initializer" }
auto m; // { dg-error "non-static data member declared" }
};
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-static8.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-static8.C
index 34aa5af..9facd0f 100644
--- a/gcc/testsuite/g++.dg/cpp0x/constexpr-static8.C
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-static8.C
@@ -3,6 +3,6 @@
// { dg-options "-fpermissive" }
struct Foo {
- static const double d = 3.14; // { dg-warning "constexpr" }
+ static const double d = 3.14; // { dg-warning "23:'constexpr' needed" }
};
-const double Foo::d; // { dg-warning "constexpr" }
+const double Foo::d;
diff --git a/gcc/testsuite/g++.dg/cpp0x/pr71248.C b/gcc/testsuite/g++.dg/cpp0x/pr71248.C
new file mode 100644
index 0000000..e996351
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/pr71248.C
@@ -0,0 +1,10 @@
+// PR c++/71248
+// { dg-do compile { target c++11 } }
+
+struct S
+{
+ int a;
+ static int S::*typeMembers[] = { // { dg-error "20:in-class initialization" }
+ &S::a,
+ };
+};
diff --git a/gcc/testsuite/g++.dg/init/new37.C b/gcc/testsuite/g++.dg/init/new37.C
index eab7854..734b141 100644
--- a/gcc/testsuite/g++.dg/init/new37.C
+++ b/gcc/testsuite/g++.dg/init/new37.C
@@ -40,7 +40,8 @@ struct T1 {
};
struct T2 {
- static const double n = 2; // { dg-error "non-integral type" }
+ static const double n = 2; // { dg-error "23:'constexpr' needed" "" { target c++11 } }
+ // { dg-error "23:ISO C\\+\\+ forbids" "" { target c++98_only } 43 }
};
struct T3 {
diff --git a/gcc/testsuite/g++.dg/template/static1.C b/gcc/testsuite/g++.dg/template/static1.C
index 98e1acb..76736ac 100644
--- a/gcc/testsuite/g++.dg/template/static1.C
+++ b/gcc/testsuite/g++.dg/template/static1.C
@@ -1,4 +1,6 @@
template <typename T> struct A
{
- static const int t[1][1]={{0}}; // { dg-error "brace-enclosed|in-class" }
+ static const int t[1][1]={{0}}; // { dg-error "20:'constexpr' needed" "" { target c++11 } }
+ // { dg-error "20:invalid in-class" "" { target c++98_only } 3 }
+ // { dg-error "28:a brace-enclosed" "" { target c++98_only } 3 }
};
diff --git a/gcc/testsuite/g++.dg/template/static2.C b/gcc/testsuite/g++.dg/template/static2.C
index 881f07c..d8ce087 100644
--- a/gcc/testsuite/g++.dg/template/static2.C
+++ b/gcc/testsuite/g++.dg/template/static2.C
@@ -4,7 +4,9 @@ template<int A::* P>
class B
{
public:
- static int A::* const p = P; // { dg-error "" }
+ static int A::* const p = P; // { dg-error "25:'constexpr' needed" "" { target c++11 } }
+ // { dg-error "25:invalid in-class" "" { target c++98_only } 7 }
+ // { dg-error "29:template parameter" "" { target c++98_only } 7 }
};
class A