LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 37585 - constexpr if condition is not a constant expression and std::is_same
Summary: constexpr if condition is not a constant expression and std::is_same
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: C++17 (show other bugs)
Version: 6.0
Hardware: PC Linux
: P enhancement
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-05-25 02:06 PDT by Krzysztof Lewko
Modified: 2018-07-03 15:16 PDT (History)
1 user (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Krzysztof Lewko 2018-05-25 02:06:18 PDT
I've found very simple case where clang gives wrong diagnosis.

Let's consider smallest possible program:
```
#include <type_traits>

int main() {
    if constexpr (std::is_same_v<int, int>) {}
    else if constexpr (std::is_same_v<double, int>) {}
}
```
clang outputs:
```
error: constexpr if condition is not a constant expression

    else if constexpr (std::is_same_v<double, int>) {}
```

Cause of this is statement:
`if constexpr (std::is_same_v<int, int>)`
any further `if constexpr` statement is not considered as constant expression.
Comment 1 Erik Pilkington 2018-06-19 06:50:22 PDT
I put a patch up here: https://reviews.llvm.org/D48322
Comment 2 Erik Pilkington 2018-07-03 15:16:05 PDT
The patch landed as r336233. Thanks for reporting this!