llvm-project/clang/test/SemaTemplate/enum-argument.cpp
Elizabeth Andrews 878a24ee24 Reapply "Fix crash on switch conditions of non-integer types in templates"
This patch reapplies commit 759948467ea. Patch was reverted due to a
clang-tidy test fail on Windows. The test has been modified. There
are no additional code changes.

Patch was tested with ninja check-all on Windows and Linux.

Summary of code changes:

Clang currently crashes for switch statements inside a template when the
condition is a non-integer field member because contextual implicit
conversion is skipped when parsing the condition. This conversion is
however later checked in an assert when the case statement is handled.
The conversion is skipped when parsing the condition because
the field member is set as type-dependent based on its containing class.
This patch sets the type dependency based on the field's type instead.

This patch fixes Bug 40982.
2019-12-03 15:27:19 -08:00

37 lines
592 B
C++

// RUN: %clang_cc1 -fsyntax-only -verify %s
enum Enum { val = 1 };
template <Enum v> struct C {
typedef C<v> Self;
};
template struct C<val>;
template<typename T>
struct get_size {
static const unsigned value = sizeof(T);
};
template<typename T>
struct X0 {
enum {
Val1 = get_size<T>::value,
Val2,
SumOfValues = Val1 + Val2
};
};
X0<int> x0i;
namespace rdar8020920 {
template<typename T>
struct X {
enum { e0 = 32 };
unsigned long long bitfield : e0;
void f(int j) {
bitfield + j; // expected-warning {{expression result unused}}
}
};
}