Files
TheRock/compiler/amd-llvm/clang/test/SemaCXX/source_location_err.cpp
T
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

106 lines
3.7 KiB
C++

// RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify -DTEST=1 %s
// RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify -DTEST=2 %s
// RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify -DTEST=3 %s
// RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify -DTEST=4 %s
// RUN: %clang_cc1 -std=c++1z -fcxx-exceptions -fexceptions -verify -DTEST=5 %s
#if TEST == 1
auto test1a = __builtin_source_location(); // expected-error {{'std::source_location::__impl' was not found}}
namespace std {
inline namespace NS {
struct source_location;
}
}
auto test1b = __builtin_source_location(); // expected-error {{'std::source_location::__impl' was not found}}
namespace std {
inline namespace NS {
struct source_location {
struct __impl;
};
}
}
auto test1c = __builtin_source_location(); // expected-error {{'std::source_location::__impl' was not found}}
#elif TEST == 2
auto test2a = __builtin_source_location(); // expected-error {{'std::source_location::__impl' was not found}}
namespace std {
inline namespace NS {
struct source_location {
struct __impl { int x; };
};
}
}
auto test2b = __builtin_source_location(); // expected-error {{'std::source_location::__impl' must be standard-layout and have only two 'const char *' fields '_M_file_name' and '_M_function_name', and two integral fields '_M_line' and '_M_column'}}
#elif TEST == 3
namespace std {
struct source_location {
struct __impl {
int other_member;
char _M_line;
const char *_M_file_name;
char _M_column;
const char *_M_function_name;
};
};
}
auto test3 = __builtin_source_location(); // expected-error {{'std::source_location::__impl' must be standard-layout and have only two 'const char *' fields '_M_file_name' and '_M_function_name', and two integral fields '_M_line' and '_M_column'}}
#elif TEST == 4
namespace std {
struct source_location {
struct parent {};
struct __impl : public parent {
char _M_line;
const char *_M_file_name;
char _M_column;
const char *_M_function_name;
};
};
}
auto test4 = __builtin_source_location(); // expected-error {{'std::source_location::__impl' must be standard-layout and have only two 'const char *' fields '_M_file_name' and '_M_function_name', and two integral fields '_M_line' and '_M_column'}}
#elif TEST == 5
namespace std {
struct source_location {
struct __impl {
signed char _M_line; // odd integral type to choose, but ok!
const char *_M_file_name;
signed char _M_column;
const char *_M_function_name;
static int other_member; // static members are OK
};
using BuiltinT = decltype(__builtin_source_location()); // OK.
};
}
// Verify that the address cannot be used as a non-type template argument.
template <auto X = __builtin_source_location()>
auto fn1() {return X;} // expected-note {{candidate template ignored: substitution failure: non-type template argument does not refer to any declaration}}
auto test5a = fn1<>(); // expected-error {{no matching function for call to 'fn1'}}
// (But using integer subobjects by value is okay.)
template <auto X = __builtin_source_location()->_M_column>
auto fn2() {return X;}
auto test5b = fn2<>();
// While it's not semantically required, for efficiency, we ensure that two
// source-locations with the same content will point to the same object. Given
// the odd definition of the struct used here (using 'signed char'), any
// line-number modulo 256 will thus have the same content, and be deduplicated.
#line 128
constexpr auto sl1 = __builtin_source_location();
#line 384
constexpr auto sl2 = __builtin_source_location();
constexpr auto sl3 = __builtin_source_location();
static_assert(sl1 == sl2);
static_assert(sl1 != sl3);
static_assert(sl1->_M_line == -128);
#endif