| 1 |
// RUN: %clang_cc1 -std=c++20 -fsyntax-only -ast-dump -verify %s | FileCheck %s |
| 2 |
|
| 3 |
// Ensure qualifiers are preserved during derived-to-base conversion. |
| 4 |
namespace PR127683 { |
| 5 |
|
| 6 |
struct Base { |
| 7 |
int Val; |
| 8 |
}; |
| 9 |
|
| 10 |
struct Derived : Base { }; |
| 11 |
|
| 12 |
// Value-initialize base class subobjects with type qualifiers. |
| 13 |
volatile Derived VObj; |
| 14 |
const Derived CObj{}; // expected-note{{variable 'CObj' declared const here}} |
| 15 |
const volatile Derived CVObj{}; // expected-note{{variable 'CVObj' declared const here}} |
| 16 |
__attribute__((address_space(1))) Derived AddrSpaceObj{}; |
| 17 |
|
| 18 |
void test_store() { |
| 19 |
// CHECK: `-ImplicitCastExpr {{.*}} 'volatile PR127683::Base' lvalue <UncheckedDerivedToBase (Base)> |
| 20 |
VObj.Val = 0; |
| 21 |
|
| 22 |
// CHECK: `-ImplicitCastExpr {{.*}} 'const PR127683::Base' lvalue <UncheckedDerivedToBase (Base)> |
| 23 |
CObj.Val = 1; // expected-error {{cannot assign to variable 'CObj' with const-qualified type 'const Derived'}} |
| 24 |
|
| 25 |
// CHECK: `-ImplicitCastExpr {{.*}} 'const volatile PR127683::Base' lvalue <UncheckedDerivedToBase (Base)> |
| 26 |
CVObj.Val = 1; // expected-error {{cannot assign to variable 'CVObj' with const-qualified type 'const volatile Derived'}} |
| 27 |
|
| 28 |
// CHECK: `-ImplicitCastExpr {{.*}} '__attribute__((address_space(1))) PR127683::Base' lvalue <UncheckedDerivedToBase (Base)> |
| 29 |
AddrSpaceObj.Val = 1; |
| 30 |
} |
| 31 |
|
| 32 |
void test_load() { |
| 33 |
// CHECK: `-ImplicitCastExpr {{.*}} <col:30> 'volatile PR127683::Base' lvalue <UncheckedDerivedToBase (Base)> |
| 34 |
[[maybe_unused]] int Val = VObj.Val; |
| 35 |
|
| 36 |
// CHECK: `-ImplicitCastExpr {{.*}} 'const PR127683::Base' lvalue <UncheckedDerivedToBase (Base)> |
| 37 |
Val = CObj.Val; |
| 38 |
|
| 39 |
// CHECK: `-ImplicitCastExpr {{.*}} 'const volatile PR127683::Base' lvalue <UncheckedDerivedToBase (Base)> |
| 40 |
Val = CVObj.Val; |
| 41 |
|
| 42 |
// CHECK: `-ImplicitCastExpr {{.*}} '__attribute__((address_space(1))) PR127683::Base' lvalue <UncheckedDerivedToBase (Base)> |
| 43 |
Val = AddrSpaceObj.Val; |
| 44 |
} |
| 45 |
|
| 46 |
} |