[Bug c++/85363] Throwing exception from member constructor (brace initializer vs initializer list)

2021-08-11 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85363

Andrew Pinski  changed:

   What|Removed |Added

 Blocks||80683
 CC||majerech.o at gmail dot com

--- Comment #10 from Andrew Pinski  ---
*** Bug 80683 has been marked as a duplicate of this bug. ***


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80683
[Bug 80683] Exceptions don't propagate through default member initializer

[Bug c++/85363] Throwing exception from member constructor (brace initializer vs initializer list)

2021-08-11 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85363

Andrew Pinski  changed:

   What|Removed |Added

   Target Milestone|--- |9.0

[Bug c++/85363] Throwing exception from member constructor (brace initializer vs initializer list)

2020-04-16 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85363

Jonathan Wakely  changed:

   What|Removed |Added

 CC||stephane.zimmermann@trust-i
   ||n-soft.com

--- Comment #9 from Jonathan Wakely  ---
*** Bug 94616 has been marked as a duplicate of this bug. ***

[Bug c++/85363] Throwing exception from member constructor (brace initializer vs initializer list)

2018-05-16 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85363

Marek Polacek  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #8 from Marek Polacek  ---
Fixed for GCC 9.

[Bug c++/85363] Throwing exception from member constructor (brace initializer vs initializer list)

2018-05-16 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85363

--- Comment #7 from Marek Polacek  ---
Author: mpolacek
Date: Wed May 16 20:37:45 2018
New Revision: 260300

URL: https://gcc.gnu.org/viewcvs?rev=260300=gcc=rev
Log:
PR c++/85363
* call.c (set_flags_from_callee): Handle AGGR_INIT_EXPRs too.
* tree.c (bot_manip): Call set_flags_from_callee for
AGGR_INIT_EXPRs too.

* g++.dg/cpp0x/initlist-throw1.C: New test.
* g++.dg/cpp0x/initlist-throw2.C: New test.

Added:
trunk/gcc/testsuite/g++.dg/cpp0x/initlist-throw1.C
trunk/gcc/testsuite/g++.dg/cpp0x/initlist-throw2.C
Modified:
trunk/gcc/cp/ChangeLog
trunk/gcc/cp/call.c
trunk/gcc/cp/tree.c
trunk/gcc/testsuite/ChangeLog

[Bug c++/85363] Throwing exception from member constructor (brace initializer vs initializer list)

2018-05-16 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85363

Marek Polacek  changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |mpolacek at gcc dot 
gnu.org

[Bug c++/85363] Throwing exception from member constructor (brace initializer vs initializer list)

2018-05-10 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85363

--- Comment #6 from Marek Polacek  ---
P::P () is marked as TREE_NOTHROW because when we're processing X::X ((struct X
*) <<< Unknown tree: void_cst >>>, 20) (which can throw) in
set_flags_from_callee, cfun is null in this case, so we don't mark P::P() as
can_throw.

If struct P were
struct P {
P () : x {5} {}
X x;
};

it would work as expected, because when processing X::X(), cfun would be
non-null, so it would be marked as can_throw.

[Bug c++/85363] Throwing exception from member constructor (brace initializer vs initializer list)

2018-05-08 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85363

--- Comment #5 from Marek Polacek  ---
In C++11, .eh optimizes out the catch, so the exception is never caught.  That
is because lower_catch doesn't think that the region may throw
(eh_region_may_contain_throw).

After further poking it seems the cause is that P::P () is marked as
TREE_NOTHROW, which seems incorrect, because it calls X::X() which calls init()
with throw.  That TREE_NOTHROW is set in finish_function:

  /* If this function can't throw any exceptions, remember that.  */
  if (!processing_template_decl
  && !cp_function_chain->can_throw
  && !flag_non_call_exceptions
  && !decl_replaceable_p (fndecl))
TREE_NOTHROW (fndecl) = 1;

[Bug c++/85363] Throwing exception from member constructor (brace initializer vs initializer list)

2018-04-13 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85363

--- Comment #4 from Jonathan Wakely  ---
That implemented the rule that aggregates can't have NSDMIs.

It started working in C++14 mode with r216750, which implements the C++14 rule
that aggregates _can_ have NSDMIs.

So the problem seems to be when it's an aggregate.

[Bug c++/85363] Throwing exception from member constructor (brace initializer vs initializer list)

2018-04-12 Thread mpolacek at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85363

Marek Polacek  changed:

   What|Removed |Added

 CC||mpolacek at gcc dot gnu.org

--- Comment #3 from Marek Polacek  ---
Started with r180965.

[Bug c++/85363] Throwing exception from member constructor (brace initializer vs initializer list)

2018-04-12 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85363

--- Comment #2 from Jonathan Wakely  ---
In C++11 mode the compiler emits a constructor for P:

;; Function constexpr P::P() (null)
;; enabled by -tree-original


{
  >>
  20 ) >;
}


And the initialization of p{} in main is different:

;; Function int main() (null)
;; enabled by -tree-original


{
  <<< Unknown tree: try_block
  {
struct P p;

struct P p;
<>> >>>) >;
  }
  <<< Unknown tree: handler

  try
{
  <;
  return  = 0;
}
  finally
{
  __cxa_end_catch ();
} >>> >>>;
  return  = 1;
}
return  = 0;


Whereas in C++14 mode p.x gets constructed directly:

;; Function int main() (null)
;; enabled by -tree-original


{
  <<< Unknown tree: try_block
  {
struct P p;

struct P p;
<>>
  20  >;
  }
  <<< Unknown tree: handler

  try
{
  <;
  return  = 0;
}
  finally
{
  __cxa_end_catch ();
} >>> >>>;
  return  = 1;
}
return  = 0;

[Bug c++/85363] Throwing exception from member constructor (brace initializer vs initializer list)

2018-04-12 Thread redi at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85363

Jonathan Wakely  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2018-04-12
 Ever confirmed|0   |1

--- Comment #1 from Jonathan Wakely  ---
Please provide *complete* testcases, not ones missing headers.

Confirmed with this:

int init (int f) {
throw f;
}

struct X {
X (int f) : n {init (f)} {}
int n;
};

struct P {
X x {20};
};

int main ()
{
try {
P p {};
}
catch (int n) {
return 0;
}
return 1;
}

It only fails in C++11 mode, not C++14 or later.