https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89553

            Bug ID: 89553
           Summary: "static const double x = 2" is treated equivalent to
                    "static constexpr double x = 2"
           Product: gcc
           Version: 8.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tadeus.prastowo at unitn dot it
  Target Milestone: ---

For the following example, requesting a strict compliance to C++17 using
"-std=c++17 -pedantic-errors", Clang rejects but GCC accepts
(https://www.godbolt.org/z/RDRdE5):

template<const double *x>
struct X {
  static constexpr double value = *x * 2;
};
static const double x = 2;
static_assert(X<&x>::value > 2);

According to the discussion at the C++ standard discussion forum (see
https://groups.google.com/a/isocpp.org/d/topic/std-discussion/i9eAYNDCr8U), GCC
behavior is wrong because C++17 standard (the draft available at
http://www.open-std.org/JTC1/SC22/WG21/docs/standards.html) says that "static
const double x = 2" cannot be treated as being equivalent to "static constexpr
double x = 2" due to the use of lvalue-to-rvalue conversion that hits the
following stipulation in [expr.const]p2,2.7,2.7.1 (page 139 of the draft):
-- 8< -----------------
An expression e is a core constant expression unless the evaluation of e,
following the rules of the abstract machine (4.6), would evaluate one of the
following expressions:
— an lvalue-to-rvalue conversion (7.1) unless it is applied to
  — a non-volatile glvalue of integral or enumeration type that refers to a
complete non-volatile const object with a preceding initialization, initialized
with a constant expression
-- 8< -----------------

Specifically, "static const double x = 2" is not "a non-volatile glvalue of
integral or enumeration type that refers to a complete non-volatile const
object with a preceding initialization, initialized with a constant expression"
due to the type "double".

Reply via email to