public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/53036] New: [c++11] trivial class fails std::is_trivial test
@ 2012-04-18 22:09 eric.niebler at gmail dot com
  2012-04-19  6:31 ` [Bug c++/53036] " marc.glisse at normalesup dot org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: eric.niebler at gmail dot com @ 2012-04-18 22:09 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 53036
           Summary: [c++11] trivial class fails std::is_trivial test
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: eric.niebler@gmail.com


In my understanding of the new C++ standard, the following code should compile.
It does not.

  struct D
  {
      D() = default;
      D(D const &) = default;
      template<typename ...U>
      constexpr D(U ...u)
      {}
  };
  static_assert(std::is_trivial<D>::value, "here");

The problem is the variadic constexpr constructor. I'm guessing here that the
problem is that it could also be used as a default constructor, making the type
non-trivial. However, I have explicitly defaulted the default constructor, so
the variadic constructr should never be considered for 0 arguments.

I base the above supposition on the fact that if I add a dummy argument to the
variadic as below, it works:

  struct D
  {
      D() = default;
      D(D const &) = default;
      template<typename ...U>
      constexpr D(int, U ...u) // dummy arg, not default c'tor, ok.
      {}
  };
  static_assert(std::is_trivial<D>::value, "here");


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

* [Bug c++/53036] [c++11] trivial class fails std::is_trivial test
  2012-04-18 22:09 [Bug c++/53036] New: [c++11] trivial class fails std::is_trivial test eric.niebler at gmail dot com
@ 2012-04-19  6:31 ` marc.glisse at normalesup dot org
  2012-04-19 12:20 ` marc.glisse at normalesup dot org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: marc.glisse at normalesup dot org @ 2012-04-19  6:31 UTC (permalink / raw)
  To: gcc-bugs

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

Marc Glisse <marc.glisse at normalesup dot org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |marc.glisse at normalesup
                   |                            |dot org

--- Comment #1 from Marc Glisse <marc.glisse at normalesup dot org> 2012-04-19 06:28:57 UTC ---
(In reply to comment #0)
> In my understanding of the new C++ standard, the following code should compile.
> It does not.
> 
>   struct D
>   {
>       D() = default;
>       D(D const &) = default;
>       template<typename ...U>
>       constexpr D(U ...u)
>       {}
>   };
>   static_assert(std::is_trivial<D>::value, "here");

With the declarations in this order, it seems easy to fix, in
grok_special_member_properties, only set TYPE_HAS_COMPLEX_DFLT to 1 if we
didn't already have TYPE_HAS_DEFAULT_CONSTRUCTOR (might have hidden issues, but
they are not obvious to me).

Now if you put the defaulted constructor after the user-provided variadic one,
it becomes much harder, and it looks like we'd have to remember one extra bit
of information: the reason why we set TYPE_HAS_COMPLEX_DFLT.


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

* [Bug c++/53036] [c++11] trivial class fails std::is_trivial test
  2012-04-18 22:09 [Bug c++/53036] New: [c++11] trivial class fails std::is_trivial test eric.niebler at gmail dot com
  2012-04-19  6:31 ` [Bug c++/53036] " marc.glisse at normalesup dot org
@ 2012-04-19 12:20 ` marc.glisse at normalesup dot org
  2012-04-19 12:28 ` daniel.kruegler at googlemail dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: marc.glisse at normalesup dot org @ 2012-04-19 12:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Marc Glisse <marc.glisse at normalesup dot org> 2012-04-19 12:14:04 UTC ---
Created attachment 27189
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27189
basic patch

The patch detects D as trivial.

Sadly, on this case:
struct A {
  A()=default;
  A(int=2);
};
it says A is trivial whereas I guess the ambiguity makes it non-trivial. That
could be solved for the traits by combining it with is_default_constructible,
but it may be problematic to let g++ internally believe that the class is
trivially default constructible. For some strange reason, in the case of an
ellipsis:
struct A {
  A()=default;
  A(...);
};
it does say: non-trivial.

Maybe the whole dance should only be done if the constructor argument is a
parameter pack (one that belongs to the function? or several packs?).


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

* [Bug c++/53036] [c++11] trivial class fails std::is_trivial test
  2012-04-18 22:09 [Bug c++/53036] New: [c++11] trivial class fails std::is_trivial test eric.niebler at gmail dot com
  2012-04-19  6:31 ` [Bug c++/53036] " marc.glisse at normalesup dot org
  2012-04-19 12:20 ` marc.glisse at normalesup dot org
@ 2012-04-19 12:28 ` daniel.kruegler at googlemail dot com
  2012-04-19 12:37 ` paolo.carlini at oracle dot com
  2015-03-24 22:20 ` paolo.carlini at oracle dot com
  4 siblings, 0 replies; 6+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2012-04-19 12:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Daniel Krügler <daniel.kruegler at googlemail dot com> 2012-04-19 12:24:12 UTC ---
(In reply to comment #2)
> Sadly, on this case:
> struct A {
>   A()=default;
>   A(int=2);
> };
> it says A is trivial whereas I guess the ambiguity makes it non-trivial.

I agree. This is correct assuming

http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1363

becomes accepted (There is little doubt for that, though).


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

* [Bug c++/53036] [c++11] trivial class fails std::is_trivial test
  2012-04-18 22:09 [Bug c++/53036] New: [c++11] trivial class fails std::is_trivial test eric.niebler at gmail dot com
                   ` (2 preceding siblings ...)
  2012-04-19 12:28 ` daniel.kruegler at googlemail dot com
@ 2012-04-19 12:37 ` paolo.carlini at oracle dot com
  2015-03-24 22:20 ` paolo.carlini at oracle dot com
  4 siblings, 0 replies; 6+ messages in thread
From: paolo.carlini at oracle dot com @ 2012-04-19 12:37 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org

--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> 2012-04-19 12:32:57 UTC ---
Maybe we should be sending patches to the mailing list... But let's add Jason
in CC.


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

* [Bug c++/53036] [c++11] trivial class fails std::is_trivial test
  2012-04-18 22:09 [Bug c++/53036] New: [c++11] trivial class fails std::is_trivial test eric.niebler at gmail dot com
                   ` (3 preceding siblings ...)
  2012-04-19 12:37 ` paolo.carlini at oracle dot com
@ 2015-03-24 22:20 ` paolo.carlini at oracle dot com
  4 siblings, 0 replies; 6+ messages in thread
From: paolo.carlini at oracle dot com @ 2015-03-24 22:20 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-03-24
     Ever confirmed|0                           |1

--- Comment #5 from Paolo Carlini <paolo.carlini at oracle dot com> ---
We are still missing the implementation of DR1363 (CD3)


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

end of thread, other threads:[~2015-03-24 20:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-18 22:09 [Bug c++/53036] New: [c++11] trivial class fails std::is_trivial test eric.niebler at gmail dot com
2012-04-19  6:31 ` [Bug c++/53036] " marc.glisse at normalesup dot org
2012-04-19 12:20 ` marc.glisse at normalesup dot org
2012-04-19 12:28 ` daniel.kruegler at googlemail dot com
2012-04-19 12:37 ` paolo.carlini at oracle dot com
2015-03-24 22:20 ` paolo.carlini at oracle dot com

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).