public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jason at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/96645] [9/10/11 Regression] std::variant default constructor
Date: Fri, 02 Apr 2021 18:20:11 +0000	[thread overview]
Message-ID: <bug-96645-4-faDC70Lq2L@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-96645-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #8 from Jason Merrill <jason at gcc dot gnu.org> ---
(In reply to Patrick Palka from comment #7)
> 
> Maybe the note in [class.mem.general]/7 is relevant:
> 
>   A complete-class context of a nested class is also a complete-class
> context of any enclosing class, if the nested class is defined within the
> member-specification of the enclosing class.
> 
> We can't determine if A is constructible until we parse the initializer for
> DataWithStruct::A::number.  And according to the above, we can't parse this
> initializer until DataWithStruct is complete.

Right.

> Looks like PR81359 is closely related.

Yes.  Perhaps PR81359 or PR88368, or both, were wrongly resolved.

We cannot correctly resolve is_nothrow_constructible<A> until we've parsed the
DMI.  Given that, we have three options:

1) Conservatively say no.
2) Optimistically guess yes.
3) Non-SFINAE error.

PR81359 changed our behavior from 3 to 1.

#2 seems the clear worst choice, as it can lead to things unexpectedly
throwing.

#3 means people have to jump through hoops to make their code compile.

#1 means silently pessimized code for anything that relies on
std::is_nothrow_constructible<A> in the rest of the translation, since the
value is permanently cached.

If we choose #1, we have another choice for is_constructible<A>: should it be
true (giving A() a throwing exception-spec) or false?

PR88368 changed our choice from true to false.

Any opinions on what our behavior should be?  Should there be an LWG issue?

This is related to CWG1890, and the general issue that we don't currently parse
on demand like we do instantiate on demand for templates.

So one workaround is to wrap DataWith* in a dummy template:

#include <type_traits>
using namespace std;

template <class Dummy = void>
struct DataWithStruct {
  struct A {
    int number = 5;
  };

  /*typename*/ is_nothrow_constructible<A>::type t = true_type{};
};

DataWithStruct<> d; // OK

or move the nested class out so we can finish parsing it before the use:

#include <variant>

void testVarStruct()
{
  struct A {
    int number = 5;
  };
  struct B {
    bool flag = false;
  };
  struct DataWithStruct {
    using Member = std::variant<A, B>;
    Member data;
  };
  auto d = DataWithStruct{};
}

  parent reply	other threads:[~2021-04-02 18:20 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-17  7:58 [Bug libstdc++/96645] New: " dev at hrookami dot icu
2020-08-17 14:21 ` [Bug c++/96645] [9/10/11 Regression] " redi at gcc dot gnu.org
2020-08-17 14:24 ` dev at hrookami dot icu
2020-08-17 14:30 ` redi at gcc dot gnu.org
2020-08-17 14:40 ` redi at gcc dot gnu.org
2020-08-18  7:49 ` dev at hrookami dot icu
2020-08-25 10:31 ` rguenth at gcc dot gnu.org
2020-10-12 12:33 ` rguenth at gcc dot gnu.org
2021-01-25 13:53 ` jakub at gcc dot gnu.org
2021-02-15 15:28 ` ppalka at gcc dot gnu.org
2021-04-02 18:20 ` jason at gcc dot gnu.org [this message]
2021-04-02 18:21 ` jason at gcc dot gnu.org
2021-04-03 11:27 ` redi at gcc dot gnu.org
2021-06-01  8:18 ` [Bug c++/96645] [9/10/11/12 " rguenth at gcc dot gnu.org
2021-09-06 19:56 ` eyalroz1 at gmx dot com
2021-11-23 17:08 ` redi at gcc dot gnu.org
2022-03-22 14:12 ` [Bug c++/96645] [9/10/11/12 Regression] [CWG2335] std::variant default constructor and unparsed DMI jason at gcc dot gnu.org
2022-03-22 16:15 ` jason at gcc dot gnu.org
2022-03-22 16:22 ` jason at gcc dot gnu.org
2022-03-22 17:31 ` ppalka at gcc dot gnu.org
2022-03-22 20:56 ` eyalroz1 at gmx dot com
2022-03-22 21:29 ` redi at gcc dot gnu.org
2022-03-23 13:36 ` jason at gcc dot gnu.org
2022-03-24 18:31 ` cvs-commit at gcc dot gnu.org
2022-03-26 23:22 ` jason at gcc dot gnu.org
2022-03-31  1:43 ` cvs-commit at gcc dot gnu.org
2022-04-01 14:00 ` cvs-commit at gcc dot gnu.org
2022-04-01 14:07 ` jason at gcc dot gnu.org
2022-04-01 14:14 ` jason at gcc dot gnu.org
2022-04-22  8:26 ` redi at gcc dot gnu.org
2022-05-15  6:35 ` [Bug c++/96645] [9/10/11/12/13 " pinskia at gcc dot gnu.org
2022-08-15  4:53 ` [Bug c++/96645] [10/11/12/13 " pinskia at gcc dot gnu.org
2023-04-26  6:55 ` [Bug c++/96645] [10/11/12/13/14 " rguenth at gcc dot gnu.org
2023-07-27  9:22 ` [Bug c++/96645] [11/12/13/14 " rguenth at gcc dot gnu.org
2024-05-21  9:10 ` [Bug c++/96645] [11/12/13/14/15 " jakub at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-96645-4-faDC70Lq2L@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).