[Bug c++/92580] New: "if constexpr" not discarding branch
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92580 Bug ID: 92580 Summary: "if constexpr" not discarding branch Product: gcc Version: 9.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: paultargosz86 at googlemail dot com Target Milestone: --- "if constexpr" uses std::is_same to check type. depending on the type its using different if-branches, that can have or have not member variables. The "discarded Branch" tries to use nonexistent membervariables and fails therefore. https://godbolt.org/z/jw_BAy differentiation: Bug 85689 is static_assert that is not proposed in "if constexpr" e.g. wg21.link/p0292
[Bug c++/92580] "if constexpr" not discarding branch
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92580 --- Comment #1 from Paul Targosz --- //examplecode without godbolt #include #include struct GW_t { }; template struct IP_t { constexpr static uint8_t a = A; constexpr static uint8_t b = B; constexpr static uint8_t c = C; constexpr static uint8_t d = D; }; template void workaround() { std::cout << "connecting to static IP " << int{my_config::a} << "." << int{my_config::b} << "." << int{my_config::c} << "." << int{my_config::d}; } int main() { // * This two lines are the different configurations using my_config = GW_t; // using my_config = IP_t<192,168,0,8>; if constexpr(std::is_same::value) { std::cout << "connecting to Gateway"; } else { // * first line should work but isn't, second line is the workaround std::cout << "connecting to static IP " << int{my_config::a} << "." << int{my_config::b} << "." << int{my_config::c} << "." << int{my_config::d}; // workaround(); } return 0; }
[Bug c++/92580] "if constexpr" not discarding branch
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92580 Paul Targosz changed: What|Removed |Added Status|RESOLVED|CLOSED --- Comment #4 from Paul Targosz --- closing issue because you're right