else if (CONSTANT_CLASS_P (t) && allow_non_constant)
/* No evaluation needed. */;
else
- t = cxx_eval_outermost_constant_expr (t, allow_non_constant,
- /*strict*/false,
- manifestly_const_eval, false, decl);
+ {
+ /* [basic.start.static] allows constant-initialization of variables with
+ static or thread storage duration even if it isn't required, but we
+ shouldn't bend the rules the same way for automatic variables. */
+ bool is_static = (decl && DECL_P (decl)
+ && (TREE_STATIC (decl) || DECL_EXTERNAL (decl)));
+ t = cxx_eval_outermost_constant_expr (t, allow_non_constant, !is_static,
+ manifestly_const_eval, false, decl);
+ }
if (TREE_CODE (t) == TARGET_EXPR)
{
tree init = TARGET_EXPR_INITIAL (t);
--- /dev/null
+// { dg-do compile { target c++14 } }
+
+struct A
+{
+ int i;
+ constexpr A(int i): i(i) {};
+};
+
+const A a = 42;
+
+constexpr int f()
+{
+ const int j = a.i; // { dg-message "'a'" }
+ return j;
+}
+
+static_assert (f() == 42,""); // { dg-error "non-constant" }
#include <string_view>
-const std::string_view
+constexpr std::string_view
patt = "World";
constexpr std::string_view
greet = "Hello, Humongous World of Wonder!!!";
-const std::wstring_view
+constexpr std::wstring_view
wpatt = L"World";
constexpr std::wstring_view