+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
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 */
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
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.
/* 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;
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);
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,
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);
: 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
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
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);
}
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))
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);
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;
}
}
}
- 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;
}
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)
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);
}
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. */
#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 }
// PR c++/42059
// { dg-do compile { target c++11 } }
-// { dg-options "" { target { ! c++14 } } }
+// { dg-options "" }
void
foo (int i)
// { dg-do compile { target c++11_only } }
-// { dg-options "-pedantic-errors" }
// C++14 features:
# 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
# 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:
// { dg-do compile { target c++98_only } }
-// { dg-options "-ansi" }
// C++11 features:
#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
--- /dev/null
+// We shouldn't define this feature macro when we complain about VLAs.
+
+#ifdef __cpp_runtime_arrays
+# error "__cpp_runtime_arrays"
+#endif
// PR c++/59271
// { dg-do compile { target c++14 } }
+// { dg-options "-Wno-vla" }
extern "C" int printf (const char *, ...);
-// { dg-do run { target c++14 } }
+// { dg-do run { target c++11 } }
+// { dg-options "-Wno-vla" }
#include <initializer_list>
+++ /dev/null
-// { 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);
// PR c++/57402
-// { dg-do compile { target c++14 } }
+// { dg-do run }
+// { dg-options "" }
int i = 2;
+++ /dev/null
-// 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" }
-}
+++ /dev/null
-// PR c++/60250
-// { dg-do compile { target c++14 } }
-
-template<typename> void foo()
-{
- typedef int T[ ([](){ return 1; }()) ]; // { dg-error "runtime bound" }
-}
+++ /dev/null
-// PR c++/60227
-// { dg-do compile { target c++14 } }
-
-void foo(int n)
-{
- int a[n];
- int (&r)[n] = {}; // { dg-error "" }
-}
// 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)
{
+++ /dev/null
-// 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 ();
-}
// 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>
// 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];
// 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
// PR c++/57408
-// { dg-do compile { target c++14 } }
+// { dg-do compile { target c++11 } }
+// { dg-options "-Wno-vla" }
template<typename Callable>
struct Impl
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=[&](){
// 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)
{
+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
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 { }
{ 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
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.
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()); }
};
#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;