[Bug c++/88628] lambda expression in static_assert in if constexpr is not evaluated
merukun1125 at docomo dot ne.jp
gcc-bugzilla@gcc.gnu.org
Fri Dec 28 14:20:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88628
merukun1125 at docomo dot ne.jp changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #6 from merukun1125 at docomo dot ne.jp ---
(In reply to Jakub Jelinek from comment #4)
> lambda is AFAIK a local class, so you need to instantiate it. So it is more
> similar to:
> #include <type_traits>
>
> template<typename T>
> constexpr bool run() { return false; }
>
> template<typename T>
> T get() {
> struct S {};
> if constexpr (std::is_same_v<int, T>) return 0;
> else static_assert(run <S> (), "Lambda expression is evaluated.");
> }
>
> int main() {
> get<int>();
> }
> which also compiles fine (and doesn't compile if you use say int or
> something non-dependent in run template-id).
I'm sorry, I was mistaken.
If a lambda expression is defined as a local class, it becomes as follows:
#include <type_traits>
template<typename T>
T get() {
struct S {
auto operator()() const -> decltype(false) {
return false;
}
};
if constexpr (std::is_same_v<int, T>) return 0;
else static_assert(S{}(), "Lambda expression is evaluated.");
}
int main() {
get<int>();
}
This code does not fail to compile because the compiler seems to need T to
determine the type of S.
https://wandbox.org/permlink/QtGF6wpvPr9rlhQ1
I was misunderstood as follows:
#include <type_traits>
struct S { // A type that does not depend on template parameter T
auto operator()() const -> decltype(false) {
return false;
}
};
template<typename T>
T get() {
if constexpr (std::is_same_v<int, T>) return 0;
else static_assert(S{}(), "Lambda expression is evaluated.");
}
int main() {
get<int>();
}
This code fail to compile.
https://wandbox.org/permlink/628XClL8M3dnkD1Q
If you do not mind, please tell me the place if there is a place where lambda
expressions are defined as local classes in n4659 or n4791.
More information about the Gcc-bugs
mailing list