Files
TheRock/compiler/amd-llvm/clang/test/Sema/attr-overflow-behavior-templates.cpp
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

72 lines
2.7 KiB
C++

// RUN: %clang_cc1 %s -fexperimental-overflow-behavior-types -verify -fsyntax-only -Wimplicit-overflow-behavior-conversion
// RUN: %clang_cc1 %s -fexperimental-overflow-behavior-types -verify -fsyntax-only -Wimplicit-overflow-behavior-conversion -fexperimental-new-constant-interpreter
template<typename T>
constexpr int template_overload_test(T) {
return 10;
}
constexpr int template_overload_test(int) {
return 20;
}
constexpr int template_overload_test(__ob_wrap int) {
return 30;
}
constexpr int template_overload_test(__ob_trap int) {
return 40;
}
void test_template_overload_resolution() {
static_assert(template_overload_test(42) == 20, "int should pick int overload");
static_assert(template_overload_test((__ob_wrap int)42) == 30, "__ob_wrap int should pick __ob_wrap int overload");
static_assert(template_overload_test((__ob_trap int)42) == 40, "__ob_trap int should pick __ob_trap int overload");
}
template<typename T>
struct MultiSpecTester {
static constexpr int value = 0;
};
template<>
struct MultiSpecTester<int> {
static constexpr int value = 1;
};
void test_choosing_generic_when_only_underlying_present() {
static_assert(MultiSpecTester<int>::value == 1, "int should match int specialization");
// OBTs don't choose template specialization based on underlying type, they should go with the generic
static_assert(MultiSpecTester<__ob_wrap int>::value == 0, "__ob_wrap int should match generic when there isn't a __ob_wrap specialization");
static_assert(MultiSpecTester<__ob_trap int>::value == 0, "__ob_trap int should match generic when there isn't a __ob_trap specialization");
}
template<typename T = int>
constexpr int only_int_template(int value) {
return value + 100;
}
void test_template_conversion_fallback() {
static_assert(only_int_template<int>(42) == 142, "int direct match should work");
// expected-warning@+1 {{passing argument of type '__ob_wrap int' to parameter of type 'int' discards overflow behavior at function boundary}}
static_assert(only_int_template<int>((__ob_wrap int)42) == 142, "__ob_wrap int implicit conversion should work");
// expected-warning@+1 {{passing argument of type '__ob_trap int' to parameter of type 'int' discards overflow behavior at function boundary}}
static_assert(only_int_template<int>((__ob_trap int)42) == 142, "__ob_trap int implicit conversion should work");
}
void simple_overload_test(int);
void simple_overload_test(__ob_wrap int);
template<typename T>
void simple_overload_test(T) {}
void test_function_vs_template_overload() {
int regular = 42;
__ob_wrap int wrapped = 42;
__ob_trap int trap = 42;
simple_overload_test(regular);
simple_overload_test(wrapped);
simple_overload_test(trap);
}