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

            Bug ID: 93705
           Summary: [C++2a] Non-type literal class template-parameter
                    types with mutable data members should not be allowed
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kevin at hart dot mn
  Target Milestone: ---

In the current implementation of C++2a, otherwise structural class types with
mutable data members are allowed as non-type template parameters.

The following sources seem to indicate that these should be rejected:
https://github.com/cplusplus/draft/blob/0354125f1cdfef949d80053528c4a1a4f74b1dea/source/templates.tex#L396
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1907r1.html

Perhaps non-const member functions should cause rejection as well? I couldn't
find anything about this.

Example:


struct Literal {
    constexpr Literal() {}

    // This is allowed (not const), but perhaps shouldn't be.
    bool has_value = false;
};

template<Literal lit>
void Test() {
    // The below will fail if uncommented, but seems different
    // from the language of the spec.

    // error: assignment of member 'Literal::has_value' in read-only object
    // lit.has_value = true; 
}

int main()
{
    Test<Literal{}>();
}

Reply via email to