Remove N3639 "array of runtime length" from -std=c++14.

gcc/cp/
	* decl.c (compute_array_index_type): VLAs are not part of C++14.
	(create_array_type_for_decl, grokdeclarator): Likewise.
	* lambda.c (add_capture): Likewise.
	* pt.c (tsubst): Likewise.
	* rtti.c (get_tinfo_decl): Likewise.
	* semantics.c (finish_decltype_type): Likewise.
	* typeck.c (cxx_sizeof_or_alignof_type): Likewise.
	(cp_build_addr_expr_1): Likewise.
	* init.c (build_vec_init): Don't throw bad_array_length.
gcc/c-family/
	* c-cppbuiltin.c (c_cpp_builtins): Define __cpp_runtime_arrays if
	we aren't complaining about VLAs.
libstdc++-v3/
	* libsupc++/new (bad_array_length): Move...
	* bad_array_length.cc: ...here.
	* cxxabi.h, eh_aux_runtime.cc (__cxa_throw_bad_array_new_length): Also
	move to bad_array_length.cc.

	* c-cppbuiltin.c (c_cpp_builtins): Define __cpp_runtime_arrays if
	we aren't complaining about VLAs.

From-SVN: r218655
This commit is contained in:
Jason Merrill 2014-12-11 22:49:13 -05:00 committed by Jason Merrill
parent 8c7e9a616e
commit 94a073b251
38 changed files with 112 additions and 230 deletions

View File

@ -1,3 +1,8 @@
2014-12-11 Jason Merrill <jason@redhat.com>
* c-cppbuiltin.c (c_cpp_builtins): Define __cpp_runtime_arrays if
we aren't complaining about VLAs.
2014-12-06 Marek Polacek <polacek@redhat.com>
PR tree-optimization/64183

View File

@ -828,6 +828,15 @@ c_cpp_builtins (cpp_reader *pfile)
and were standardized for C++14. */
if (!pedantic || cxx_dialect > cxx11)
cpp_define (pfile, "__cpp_binary_literals=201304");
/* Arrays of runtime bound were removed from C++14, but we still
support GNU VLAs. Let's define this macro to a low number
(corresponding to the initial test release of GNU C++) if we won't
complain about use of VLAs. */
if (c_dialect_cxx ()
&& (pedantic ? warn_vla == 0 : warn_vla <= 0))
cpp_define (pfile, "__cpp_runtime_arrays=198712");
if (cxx_dialect >= cxx11)
{
/* Set feature test macros for C++11 */
@ -863,9 +872,6 @@ c_cpp_builtins (cpp_reader *pfile)
cpp_define (pfile, "__cpp_variable_templates=201304");
cpp_define (pfile, "__cpp_digit_separators=201309");
//cpp_define (pfile, "__cpp_sized_deallocation=201309");
/* We'll have to see where runtime arrays wind up.
Let's put it in C++14 for now. */
cpp_define (pfile, "__cpp_runtime_arrays=201304");
}
}
/* Note that we define this for C as well, so that we know if

View File

@ -1,5 +1,16 @@
2014-12-11 Jason Merrill <jason@redhat.com>
Remove N3639 "array of runtime length" from -std=c++14.
* decl.c (compute_array_index_type): VLAs are not part of C++14.
(create_array_type_for_decl, grokdeclarator): Likewise.
* lambda.c (add_capture): Likewise.
* pt.c (tsubst): Likewise.
* rtti.c (get_tinfo_decl): Likewise.
* semantics.c (finish_decltype_type): Likewise.
* typeck.c (cxx_sizeof_or_alignof_type): Likewise.
(cp_build_addr_expr_1): Likewise.
* init.c (build_vec_init): Don't throw bad_array_length.
PR c++/64248
Revert:
* parser.c (cp_parser_unqualified_id): Handle __func__ here.

View File

@ -8515,7 +8515,7 @@ compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
/* We don't allow VLAs at non-function scopes, or during
tentative template substitution. */
|| !at_function_scope_p ()
|| (cxx_dialect < cxx14 && !(complain & tf_error)))
|| !(complain & tf_error))
{
if (!(complain & tf_error))
return error_mark_node;
@ -8527,7 +8527,7 @@ compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
error ("size of array is not an integral constant-expression");
size = integer_one_node;
}
else if (cxx_dialect < cxx14 && pedantic && warn_vla != 0)
else if (pedantic && warn_vla != 0)
{
if (name)
pedwarn (input_location, OPT_Wvla, "ISO C++ forbids variable length array %qD", name);
@ -8585,25 +8585,12 @@ compute_array_index_type (tree name, tree size, tsubst_flags_t complain)
stabilize_vla_size (itype);
if (cxx_dialect >= cxx14 && flag_exceptions)
if (flag_sanitize & SANITIZE_VLA
&& current_function_decl != NULL_TREE
&& !lookup_attribute ("no_sanitize_undefined",
DECL_ATTRIBUTES
(current_function_decl)))
{
/* If the VLA bound is larger than half the address space,
or less than zero, throw std::bad_array_length. */
tree comp = build2 (LT_EXPR, boolean_type_node, itype,
ssize_int (-1));
comp = build3 (COND_EXPR, void_type_node, comp,
throw_bad_array_length (), void_node);
finish_expr_stmt (comp);
}
else if (flag_sanitize & SANITIZE_VLA
&& current_function_decl != NULL_TREE
&& !lookup_attribute ("no_sanitize_undefined",
DECL_ATTRIBUTES
(current_function_decl)))
{
/* From C++14 onwards, we throw an exception on a negative
length size of an array; see above. */
/* We have to add 1 -- in the ubsan routine we generate
LE_EXPR rather than LT_EXPR. */
tree t = fold_build2 (PLUS_EXPR, TREE_TYPE (itype), itype,
@ -8730,10 +8717,6 @@ create_array_type_for_decl (tree name, tree type, tree size)
return error_mark_node;
}
if (cxx_dialect >= cxx14 && array_of_runtime_bound_p (type)
&& (flag_iso || warn_vla > 0))
pedwarn (input_location, OPT_Wvla, "array of array of runtime bound");
/* Figure out the index type for the array. */
if (size)
itype = compute_array_index_type (name, size, tf_warning_or_error);
@ -9984,13 +9967,6 @@ grokdeclarator (const cp_declarator *declarator,
: G_("cannot declare pointer to qualified function type %qT"),
type);
if (cxx_dialect >= cxx14 && array_of_runtime_bound_p (type)
&& (flag_iso || warn_vla > 0))
pedwarn (input_location, OPT_Wvla,
declarator->kind == cdk_reference
? G_("reference to array of runtime bound")
: G_("pointer to array of runtime bound"));
/* When the pointed-to type involves components of variable size,
care must be taken to ensure that the size evaluation code is
emitted early enough to dominate all the possible later uses
@ -10341,11 +10317,6 @@ grokdeclarator (const cp_declarator *declarator,
type = error_mark_node;
}
if (cxx_dialect >= cxx14 && array_of_runtime_bound_p (type)
&& (flag_iso || warn_vla > 0))
pedwarn (input_location, OPT_Wvla,
"typedef naming array of runtime bound");
if (decl_context == FIELD)
decl = build_lang_decl (TYPE_DECL, unqualified_id, type);
else

View File

@ -3591,10 +3591,7 @@ build_vec_init (tree base, tree maxindex, tree init,
if (length_check)
{
tree throw_call;
if (array_of_runtime_bound_p (atype))
throw_call = throw_bad_array_length ();
else
throw_call = throw_bad_array_new_length ();
throw_call = throw_bad_array_new_length ();
length_check = build3 (COND_EXPR, void_type_node, length_check,
throw_call, void_node);
finish_expr_stmt (length_check);

View File

@ -485,7 +485,7 @@ add_capture (tree lambda, tree id, tree orig_init, bool by_reference_p,
}
else if (variably_modified_type_p (type, NULL_TREE))
{
error ("capture of variable-size type %qT that is not a C++14 array "
error ("capture of variable-size type %qT that is not an N3639 array "
"of runtime bound", type);
if (TREE_CODE (type) == ARRAY_TYPE
&& variably_modified_type_p (TREE_TYPE (type), NULL_TREE))

View File

@ -12241,21 +12241,6 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl)
r = cp_build_reference_type (type, TYPE_REF_IS_RVALUE (t));
r = cp_build_qualified_type_real (r, cp_type_quals (t), complain);
if (cxx_dialect >= cxx14
&& !(TREE_CODE (t) == REFERENCE_TYPE && REFERENCE_VLA_OK (t))
&& array_of_runtime_bound_p (type)
&& (flag_iso || warn_vla > 0))
{
if (complain & tf_warning_or_error)
pedwarn
(input_location, OPT_Wvla,
code == REFERENCE_TYPE
? G_("cannot declare reference to array of runtime bound")
: G_("cannot declare pointer to array of runtime bound"));
else
r = error_mark_node;
}
if (r != error_mark_node)
/* Will this ever be needed for TYPE_..._TO values? */
layout_type (r);

View File

@ -396,12 +396,9 @@ get_tinfo_decl (tree type)
if (variably_modified_type_p (type, /*fn=*/NULL_TREE))
{
if (array_of_runtime_bound_p (type))
error ("typeid of array of runtime bound");
else
error ("cannot create type information for type %qT because "
"it involves types of variable size",
type);
error ("cannot create type information for type %qT because "
"it involves types of variable size",
type);
return error_mark_node;
}

View File

@ -7239,16 +7239,6 @@ finish_decltype_type (tree expr, bool id_expression_or_member_access_p,
}
}
if (cxx_dialect >= cxx14 && array_of_runtime_bound_p (type)
&& (flag_iso || warn_vla > 0))
{
if (complain & tf_warning_or_error)
pedwarn (input_location, OPT_Wvla,
"taking decltype of array of runtime bound");
else
return error_mark_node;
}
return type;
}

View File

@ -920,7 +920,8 @@ build_array_of_n_type (tree elt, int n)
return build_cplus_array_type (elt, build_index_type (size_int (n - 1)));
}
/* True iff T is a C++14 array of runtime bound (VLA). */
/* True iff T is an N3639 array of runtime bound (VLA). These were
approved for C++14 but then removed. */
bool
array_of_runtime_bound_p (tree t)

View File

@ -1578,16 +1578,6 @@ cxx_sizeof_or_alignof_type (tree type, enum tree_code op, bool complain)
return value;
}
if (cxx_dialect >= cxx14 && array_of_runtime_bound_p (type)
&& (flag_iso || warn_vla > 0))
{
if (complain)
pedwarn (input_location, OPT_Wvla,
"taking sizeof array of runtime bound");
else
return error_mark_node;
}
return c_sizeof_or_alignof_type (input_location, complete_type (type),
op == SIZEOF_EXPR, false,
complain);
@ -5540,18 +5530,7 @@ cp_build_addr_expr_1 (tree arg, bool strict_lvalue, tsubst_flags_t complain)
}
if (argtype != error_mark_node)
{
if (cxx_dialect >= cxx14 && array_of_runtime_bound_p (argtype)
&& (flag_iso || warn_vla > 0))
{
if (complain & tf_warning_or_error)
pedwarn (input_location, OPT_Wvla,
"taking address of array of runtime bound");
else
return error_mark_node;
}
argtype = build_pointer_type (argtype);
}
argtype = build_pointer_type (argtype);
/* In a template, we are processing a non-dependent expression
so we can just form an ADDR_EXPR with the correct type. */

View File

@ -5,4 +5,4 @@
#include <new>
__attribute__((visibility("hidden")))void*operator new(std::size_t); // { dg-warning "visibility attribute ignored" }
// { dg-message "previous declaration" "" { target *-*-* } 128 }
// { dg-message "previous declaration" "" { target *-*-* } 111 }

View File

@ -1,6 +1,6 @@
// PR c++/42059
// { dg-do compile { target c++11 } }
// { dg-options "" { target { ! c++14 } } }
// { dg-options "" }
void
foo (int i)

View File

@ -1,5 +1,4 @@
// { dg-do compile { target c++11_only } }
// { dg-options "-pedantic-errors" }
// C++14 features:

View File

@ -133,6 +133,14 @@
# error "__cpp_binary_literals != 201304"
#endif
// GNU VLA support:
#ifndef __cpp_runtime_arrays
# error "__cpp_runtime_arrays"
#elif __cpp_runtime_arrays != 198712
# error "__cpp_runtime_arrays != 198712"
#endif
// C++11 attributes:
#ifdef __has_cpp_attribute

View File

@ -187,12 +187,12 @@
# error "__cpp_sized_deallocation"
#endif
// Array TS features:
// GNU VLA support:
#ifndef __cpp_runtime_arrays
# error "__cpp_runtime_arrays"
#elif __cpp_runtime_arrays != 201304
# error "__cpp_runtime_arrays != 201304"
#elif __cpp_runtime_arrays != 198712
# error "__cpp_runtime_arrays != 198712"
#endif
// C++11 attributes:

View File

@ -1,5 +1,4 @@
// { dg-do compile { target c++98_only } }
// { dg-options "-ansi" }
// C++11 features:

View File

@ -22,3 +22,11 @@
#elif __cpp_binary_literals != 201304
# error "__cpp_binary_literals != 201304"
#endif
// GNU VLA support:
#ifndef __cpp_runtime_arrays
# error "__cpp_runtime_arrays"
#elif __cpp_runtime_arrays != 198712
# error "__cpp_runtime_arrays != 198712"
#endif

View File

@ -0,0 +1,5 @@
// We shouldn't define this feature macro when we complain about VLAs.
#ifdef __cpp_runtime_arrays
# error "__cpp_runtime_arrays"
#endif

View File

@ -1,5 +1,6 @@
// PR c++/59271
// { dg-do compile { target c++14 } }
// { dg-options "-Wno-vla" }
extern "C" int printf (const char *, ...);

View File

@ -1,4 +1,5 @@
// { dg-do run { target c++14 } }
// { dg-do run { target c++11 } }
// { dg-options "-Wno-vla" }
#include <initializer_list>

View File

@ -1,40 +0,0 @@
// { dg-do compile { target c++14 } }
#include <typeinfo>
void f(int n)
{
int a[n];
int aa[n][n]; // { dg-error "" }
&a; // { dg-error "" }
sizeof a; // { dg-error "" }
typeid(a); // { dg-error "" }
decltype(a) a2; // { dg-error "" }
typedef int at[n]; // { dg-error "" }
int (*p)[n]; // { dg-error "" }
int (&r)[n] = a; // { dg-error "" }
struct A
{
int a[n]; // { dg-error "" }
};
}
template <class T>
void g(int n)
{
int a[n];
int aa[n][n]; // { dg-error "" }
&a; // { dg-error "" }
sizeof a; // { dg-error "" }
typeid(a); // { dg-error "" }
decltype(a) a2; // { dg-error "" }
typedef int at[n]; // { dg-error "" }
int (*p)[n]; // { dg-error "" }
int (&r)[n] = a; // { dg-error "" }
struct A
{
int a[n]; // { dg-error "" }
};
}
template void g<int>(int);

View File

@ -1,5 +1,6 @@
// PR c++/57402
// { dg-do compile { target c++14 } }
// { dg-do run }
// { dg-options "" }
int i = 2;

View File

@ -1,8 +0,0 @@
// PR c++/60251
// { dg-do compile { target c++14 } }
void foo(int n)
{
int x[n];
[&x]() { decltype(x) y; }; // { dg-error "decltype of array of runtime bound" }
}

View File

@ -1,7 +0,0 @@
// PR c++/60250
// { dg-do compile { target c++14 } }
template<typename> void foo()
{
typedef int T[ ([](){ return 1; }()) ]; // { dg-error "runtime bound" }
}

View File

@ -1,8 +0,0 @@
// PR c++/60227
// { dg-do compile { target c++14 } }
void foo(int n)
{
int a[n];
int (&r)[n] = {}; // { dg-error "" }
}

View File

@ -1,5 +1,6 @@
// N3639 allows initialization and capture of VLAs
// { dg-do run { target c++14 } }
// { dg-do run { target c++11 } }
// { dg-options "-Wno-vla" }
void f(int n)
{

View File

@ -1,29 +0,0 @@
// Test for throwing bad_array_length on invalid array length
// { dg-do run { target c++14 } }
#include <new>
int f(int i)
{
int ar[i]{1,2,3,4};
return ar[i-1];
}
void g(int i)
{
int ar[i];
ar[0] = 42;
}
int main()
{
int ok = 0;
f(4); // OK
try { f(3); } // too small
catch (std::bad_array_length) { ++ok; }
try { g(-24); } // negative
catch (std::bad_array_length) { ++ok; }
if (ok != 2)
__builtin_abort ();
}

View File

@ -1,5 +1,6 @@
// Test for range-based for with VLAs.
// { dg-do run { target c++14 } }
// { dg-do run { target c++11 } }
// { dg-options "-Wno-vla" }
#include <new>

View File

@ -1,5 +1,6 @@
// PR c++/55149
// { dg-do compile { target c++14 } }
// { dg-do compile { target c++11 } }
// { dg-options "-Wno-vla" }
void test(int n) {
int r[n];

View File

@ -1,5 +1,6 @@
// PR c++/55149
// { dg-do compile { target c++14 } }
// { dg-do compile { target c++11 } }
// { dg-options "-Wno-vla" }
template<unsigned int TA>
struct SA

View File

@ -1,5 +1,6 @@
// PR c++/57408
// { dg-do compile { target c++14 } }
// { dg-do compile { target c++11 } }
// { dg-options "-Wno-vla" }
template<typename Callable>
struct Impl
@ -19,7 +20,7 @@ extern "C" int printf(const char*, ...);
int main(){
int y = 2;
float fa[2][y]; // { dg-error "array of array of runtime bound" }
float fa[2][y];
fa[0][0]=0.8;
fa[0][1]=1.8;
auto fx=[&](){

View File

@ -1,6 +1,6 @@
// Test that auto works with VLAs.
// { dg-do compile { target c++11 } }
// { dg-options "" { target { ! c++14 } } }
// { dg-options "-Wno-vla" }
void bar(int n)
{

View File

@ -1,3 +1,10 @@
2014-12-11 Jason Merrill <jason@redhat.com>
* libsupc++/new (bad_array_length): Move...
* bad_array_length.cc: ...here.
* cxxabi.h, eh_aux_runtime.cc (__cxa_throw_bad_array_new_length): Also
move to bad_array_length.cc.
2014-12-11 Jonathan Wakely <jwakely@redhat.com>
* testsuite/30_threads/condition_variable/members/3.cc: Only use

View File

@ -25,6 +25,20 @@
namespace std
{
// From N3639. This was voted in and then back out of C++14, and is now
// just here for backward link compatibility with code built with 4.9.
class bad_array_length : public bad_alloc
{
public:
bad_array_length() throw() { };
// This declaration is not useless:
// http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
virtual ~bad_array_length() throw();
// See comment in eh_exception.cc.
virtual const char* what() const throw();
};
bad_array_length::~bad_array_length() _GLIBCXX_USE_NOEXCEPT { }
@ -33,3 +47,11 @@ bad_array_length::what() const _GLIBCXX_USE_NOEXCEPT
{ return "std::bad_array_length"; }
} // namespace std
namespace __cxxabiv1 {
extern "C" void
__cxa_throw_bad_array_length ()
{ _GLIBCXX_THROW_OR_ABORT(std::bad_array_length()); }
} // namespace __cxxabiv1

View File

@ -154,9 +154,6 @@ namespace __cxxabiv1
void
__cxa_throw_bad_array_new_length() __attribute__((__noreturn__));
void
__cxa_throw_bad_array_length() __attribute__((__noreturn__));
/**
* @brief Demangling routine.
* ABI-mandated entry point in the C++ runtime library for demangling.

View File

@ -40,7 +40,3 @@ __cxxabiv1::__cxa_bad_typeid ()
extern "C" void
__cxxabiv1::__cxa_throw_bad_array_new_length ()
{ _GLIBCXX_THROW_OR_ABORT(std::bad_array_new_length()); }
extern "C" void
__cxxabiv1::__cxa_throw_bad_array_length ()
{ _GLIBCXX_THROW_OR_ABORT(std::bad_array_length()); }

View File

@ -79,23 +79,6 @@ namespace std
};
#endif
// We throw this exception for GNU VLAs of negative length in all C++
// dialects, so declare it if we aren't in strict conformance mode.
#if __cplusplus > 201103L || !defined(__STRICT_ANSI__)
class bad_array_length : public bad_alloc
{
public:
bad_array_length() throw() { };
// This declaration is not useless:
// http://gcc.gnu.org/onlinedocs/gcc-3.0.2/gcc_6.html#SEC118
virtual ~bad_array_length() throw();
// See comment in eh_exception.cc.
virtual const char* what() const throw();
};
#endif
struct nothrow_t { };
extern const nothrow_t nothrow;