re PR c++/51401 ([c++0x] [4.7 Regression] ICE with invalid use of auto in template)

PR c++/51401
	* decl.c (grokdeclarator): Error for auto on non-static data members.

	* g++.dg/cpp0x/auto7.C: Adjust expected error message.
	* g++.dg/cpp0x/auto29.C: New test.

From-SVN: r182097
This commit is contained in:
Jakub Jelinek 2011-12-08 01:50:26 +01:00 committed by Jakub Jelinek
parent 2df708d937
commit a633b93ea3
5 changed files with 39 additions and 1 deletions

View File

@ -1,5 +1,8 @@
2011-12-07 Jakub Jelinek <jakub@redhat.com>
PR c++/51401
* decl.c (grokdeclarator): Error for auto on non-static data members.
PR c++/51429
* typeck2.c (cxx_incomplete_type_diagnostic): Don't
ICE if TREE_OPERAND (value, 1) is overloaded.

View File

@ -9971,6 +9971,12 @@ grokdeclarator (const cp_declarator *declarator,
}
else if (decl_context == FIELD)
{
if (!staticp && type_uses_auto (type))
{
error ("non-static data member declared %<auto%>");
type = error_mark_node;
}
/* The C99 flexible array extension. */
if (!staticp && TREE_CODE (type) == ARRAY_TYPE
&& TYPE_DOMAIN (type) == NULL_TREE)

View File

@ -1,5 +1,9 @@
2011-12-07 Jakub Jelinek <jakub@redhat.com>
PR c++/51401
* g++.dg/cpp0x/auto7.C: Adjust expected error message.
* g++.dg/cpp0x/auto29.C: New test.
PR c++/51429
* g++.dg/parse/error45.C: New test.

View File

@ -0,0 +1,25 @@
// PR c++/51401
// { dg-do compile }
// { dg-options "-std=c++11" }
template <int>
struct A
{
auto i; // { dg-error "non-static data member declared" }
};
template <int>
struct B
{
auto i = 0; // { dg-error "non-static data member declared" }
};
struct C
{
auto i; // { dg-error "non-static data member declared" }
};
struct D
{
auto i = 0; // { dg-error "non-static data member declared" }
};

View File

@ -9,5 +9,5 @@ template<int> struct A
{
static auto k = 7; // { dg-error "non-const" }
static auto l; // { dg-error "has no initializer" }
auto m; // { dg-error "has no initializer" }
auto m; // { dg-error "non-static data member declared" }
};