Title
constexpr conversion functions and non-type template arguments
Status
c++11
Section
7.7 [expr.const]
Submitter
Jason Merrill

Created on 2010-08-01.00:00:00 last changed 123 months ago

Messages

Date: 2011-03-15.00:00:00

[Voted into the WP at the March, 2011 meeting as part of paper N3260.]

Date: 2011-02-15.00:00:00

Proposed resolution (February, 2011):

This issue is resolved by the resolution of issue 1197.

Date: 2010-08-01.00:00:00

According to 13.4.3 [temp.arg.nontype] paragraph 1, one of the possibilities for a template-argument for a non-type, non-template template-parameter is

  • an integral constant expression (including a constant expression of literal class type that can be used as an integral constant expression as described in 7.7 [expr.const])

However, the requirement for such a literal class type is (7.7 [expr.const] paragraph 5):

...that class type shall have a single non-explicit conversion function to an integral or enumeration type and that conversion function shall be constexpr.

Note that this normative requirement for a single conversion function is contradicted by the example in that paragraph, which reads in significant part,

    struct A {
      constexpr A(int i) : val(i) { }
      constexpr operator int() { return val; }
      constexpr operator long() { return 43; }
    private:
      int val;
    };
    template<int> struct X { };
    constexpr A a = 42;
    X<a> x; // OK: unique conversion to int
History
Date User Action Args
2014-03-03 00:00:00adminsetstatus: fdis -> c++11
2011-04-10 00:00:00adminsetmessages: + msg3317
2011-04-10 00:00:00adminsetstatus: tentatively ready -> fdis
2011-02-28 00:00:00adminsetmessages: + msg3226
2011-02-28 00:00:00adminsetstatus: drafting -> tentatively ready
2010-11-29 00:00:00adminsetstatus: open -> drafting
2010-08-01 00:00:00admincreate