This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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

            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 gnu.org
          Reporter: apyszczuk at gmail dot com
  Target Milestone: ---

https://stackoverflow.com/questions/48909833/throwing-exception-from-member-constructor-brace-initializer-vs-initializer-lis



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
different:

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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]