public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/47774] New: [C++0x] constexpr specifier on ctor not ignored when template instantiation causes ctor to not satify constexpr requirements
@ 2011-02-16 22:44 dev.lists at jessamine dot co.uk
  2011-02-16 23:12 ` [Bug c++/47774] " dev.lists at jessamine dot co.uk
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: dev.lists at jessamine dot co.uk @ 2011-02-16 22:44 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47774

           Summary: [C++0x] constexpr specifier on ctor not ignored when
                    template instantiation causes ctor to not satify
                    constexpr requirements
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: dev.lists@jessamine.co.uk


The definition of b in the program below fails to compile due to the default
constructor for its only member not being a valid constexpr.  B itself does not
claim to be a literal type or that instances of it should be usable as
constants but g++ currently seems to enforce the constexpr nature of the ctor
of X<T> even when T causes the definition to fail to meet the constexpr
constructor requirements.

7.1.5 para 4 states:

  6  If the instantiated template specialization of a constexpr
     function template or member function of a class template would
     fail to satisfy the requirements for a constexpr function or
     constexpr constructor, that specialization is not a constexpr
     function or constexpr constructor. [Note: if the function is
     a member function it will still be const as described below.
     Implementations are encouraged to issue a warning if a
     function is rendered not constexpr by a non-dependent
     construct.  --end note]

The program below demonstrates what I think to be non-compliance with this.  It
is a reduced case (I originally came across this when attempting to instantiate
a std::array<std::pair<F,S>,N> where objects of either F or S were not usable
as constants; pair's default constructor is specified as constexpr yielding the
same problem).

template <typename T>
struct X
{
   constexpr X() : t() {}
   T t;
};

struct CanBeCompileTimeConstant     { constexpr CanBeCompileTimeConstant() {}
};
struct CannotBeCompileTimeConstant  { CannotBeCompileTimeConstant() {} };

X<CanBeCompileTimeConstant> nonconstexpr1;
X<CannotBeCompileTimeConstant> nonconstexpr2;
constexpr X<CanBeCompileTimeConstant> constexpr1;
//constexpr X<CannotBeCompileTimeConstant> constexpr2; // fails as expected

struct A
{
   X<CanBeCompileTimeConstant> mem;
};

struct B
{
   X<CannotBeCompileTimeConstant> mem;
};

A a;
B b; // fails unexpectedly: 'constexpr X<T>::X() [with T =
CannotBeCompileTimeConstant]' is not 'constexpr'


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2011-03-03  8:40 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-16 22:44 [Bug c++/47774] New: [C++0x] constexpr specifier on ctor not ignored when template instantiation causes ctor to not satify constexpr requirements dev.lists at jessamine dot co.uk
2011-02-16 23:12 ` [Bug c++/47774] " dev.lists at jessamine dot co.uk
2011-02-17  8:38 ` dev.lists at jessamine dot co.uk
2011-02-17 11:30 ` dev.lists at jessamine dot co.uk
2011-02-17 12:46 ` redi at gcc dot gnu.org
2011-02-21  0:23 ` paolo.carlini at oracle dot com
2011-02-21  3:15 ` jason at gcc dot gnu.org
2011-03-01 15:34 ` dev.lists at jessamine dot co.uk
2011-03-03  2:49 ` jason at gcc dot gnu.org
2011-03-03  8:40 ` dev.lists at jessamine dot co.uk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).