[clang] [clang][Sema] Propagate `volatile` during derived-to-base conversion (PR #127824)

Antonio Frighetto via cfe-commits cfe-commits at lists.llvm.org
Sat Feb 22 07:29:42 PST 2025


================
@@ -3107,8 +3107,11 @@ Sema::PerformObjectMemberConversion(Expr *From,
                                    /*IgnoreAccess=*/true))
     return ExprError();
 
-  return ImpCastExprToType(From, DestType, CK_UncheckedDerivedToBase,
-                           VK, &BasePath);
+  if (FromType.isVolatileQualified())
+    DestType.addVolatile();
----------------
antoniofrighetto wrote:

>From intro.object:
> Objects can contain other objects, called subobjects. A subobject can be a member subobject a base class subobject, or an array element.

So, given:
```cpp
struct Base { int X; };
struct Derived : Base {};

const Derived Obj;
```
Seems outright logical that the entirety of Obj must be const. Thought this applied only for cv-qualifiers, but should indeed make sense for all qualifiers; updated, thanks!

https://github.com/llvm/llvm-project/pull/127824


More information about the cfe-commits mailing list