[llvm-bugs] [Bug 34009] New: Clang 5.0 consider template method unevaluated and accepts this code, GCC rejects it
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Jul 31 14:38:20 PDT 2017
https://bugs.llvm.org/show_bug.cgi?id=34009
Bug ID: 34009
Summary: Clang 5.0 consider template method unevaluated and
accepts this code, GCC rejects it
Product: clang
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: C++11
Assignee: unassignedclangbugs at nondot.org
Reporter: joker.eph at gmail.com
CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
Clang accepts the following (C++11) code while GCC rejects it (4.9 to 7.0).
Clang seems to consider that the constexpr `IS_N` is enough to make the method
`bar()` unevaluated, while gcc complains. I don't understand what makes clang
happy here?
Changing the define makes both compiler happy, as the constexpr is dependent on
the template args.
#include <type_traits>
#define INDEPENDENT_CONSTEXPR 1
template<int N = 1>
struct Bar {
typename std::enable_if<N != 1, void>::type foo() {
}
};
template<int N = 1>
struct Foo {
#if INDEPENDENT_CONSTEXPR
static constexpr bool IS_N = true;
#else
static constexpr bool IS_N = (N == 1);
#endif
// (N == 1);
using myBar = Bar<IS_N>;
void bar() {
myBar b;
b.foo();
}
};
void foobar() {
Foo<0> f0;
Foo<1> f1;
#if !INDEPENDENT_CONSTEXPR
f0.bar();
#endif
// Following should never work
// f1.bar();
}
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170731/111c623a/attachment-0001.html>
More information about the llvm-bugs
mailing list