diff --git a/clang/test/Analysis/Inputs/system-header-simulator-cxx.h b/clang/test/Analysis/Inputs/system-header-simulator-cxx.h --- a/clang/test/Analysis/Inputs/system-header-simulator-cxx.h +++ b/clang/test/Analysis/Inputs/system-header-simulator-cxx.h @@ -1253,3 +1253,11 @@ }; } // namespace std + +// C++17 std::byte +#if __cplusplus >= 201703L +namespace std { + enum class byte : unsigned char {}; +} // namespace std +#endif + diff --git a/clang/test/Analysis/enum-cast-out-of-range-c++17.cpp b/clang/test/Analysis/enum-cast-out-of-range-c++17.cpp new file mode 100644 --- /dev/null +++ b/clang/test/Analysis/enum-cast-out-of-range-c++17.cpp @@ -0,0 +1,26 @@ +// RUN: %clang_analyze_cc1 \ +// RUN: -analyzer-checker=core,alpha.cplusplus.EnumCastOutOfRange \ +// RUN: -std=c++17 -verify %s +// +// Test relaxed enum class initialization. +// + +// expected-no-diagnostics + +#include "Inputs/system-header-simulator-cxx.h" + +void test_direct_list_init() { + std::byte b{0}; // OK + (void)b; +} + +void test_copy_init() { + std::byte b = std::byte{0}; // OK + (void)b; +} + +struct A { std::byte b; }; +void test_aggregate_copy_init() { + A a = {std::byte{42}}; // OK + (void)a; +}