Bug ID: 85363
           Summary: Throwing exception from member constructor (brace
                    initializer vs initializer list)
           Product: gcc
           Version: 7.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot
          Reporter: apyszczuk at gmail dot com
  Target Milestone: ---

int init (int f) {
    throw f;

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

struct P {
    X x {20};

int main (int, char** argv) {
    try {
        P p {};
    catch (int n) {
        std::cout << n << "\n";

This code (C++11 mode) compiles fine (using GCC 7.2.1) and under the Linux
(Centos 7.4.1708) I get:

terminate called after throwing an instance of 'int'
[1]    1242 abort (core dumped)  ./main

If I compile this code with C++14 or C++17, catch branch was taken.

I have tracked the issue, meaning that when my P class looks a little bit

struct P {
    P (int f) : x {f} {}
    X x;

This code compiled with C++11/14/17 works as expected.

For both examples I compiled it with -Wall -Wextra -Wpedantic

Reply via email to