https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89785
Bug ID: 89785
Summary: Incorrect "not a constant expression" error with
switch statement that returns
Product: gcc
Version: 9.0
Status: UNCONFIRMED
Keywords: rejects-valid
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: antoshkka at gmail dot com
Target Milestone: ---
The following code fails to compile:
constexpr int Addrlen(int domain) {
switch (domain) {
case 0:
return 0;
case 2:
return 42;
}
throw 42;
}
Error message is following:
<source>: In function 'constexpr int Addrlen(int)':
<source>:8:11: error: expression '<throw-expression>' is not a constant
expression
8 | throw 42;
| ^~