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

            Bug ID: 82226
           Summary: previously instantiation of template<auto> type breaks
                    future use
           Product: gcc
           Version: 7.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: john at mcfarlane dot name
  Target Milestone: ---

The following fragment fails to compile because the second `static_assert`
fires incorrectly. Removing the first `static_assert` causes the code to
compile successfully.

    #include <type_traits>

    template<auto Value>
    struct constant {
        static constexpr decltype(Value) value{};
    };

    // if this line is commented out, the last line compiles OK
    static_assert(!constant<0>::value);

    static_assert(std::is_same_v<long, decltype(+constant<0L>::value)>);

Setup: CompilerExplorer with x86-64 GCC 7.1.0 and 7.2.0
(https://godbolt.org/g/KE9uXB) and on Intel(R) Xeon(R) CPU E5-2676 v3 with GCC
7.2.0 compiled from source.

Flags: -std=c++17

Result: second static_assert fails because the `decltype` expression resolves
to `int`.

Expected: `decltype` result should be `long`. The first `static_assert`
statement should not influence the second.

Notes:
1. The type of the literal used in the first `static_assert` seems to determine
the type to which the second `decltype` resolves. For instance, replacing `0`
with `0LL` and `long` with `long long` prevents the compiler error.
2. Observer the operators used in both `static_assert` statements: `!` and `+`.
These are necessary. Other operators will cause the error but without
operators, there is no error.

Reply via email to