[clang] [clang] Fix array types comparison in getCommonSugaredType (PR #131649)

Matheus Izvekov via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 17 11:51:29 PDT 2025


mizvekov wrote:

The test for this should actually go in `clang/test/SemaCXX/sugar-common-types.cpp`, following the style in the file.

One example test, without using constexpr: https://godbolt.org/z/8PGa4aTPx
```C++
enum class Z {};

using ConstInt = const int;
using ConstIntArray1 = ConstInt[1];
using ConstIntArrayInc = ConstInt[];

const ConstIntArray1 c = { 5 };
const ConstIntArrayInc d = { 0 };
Z t1 = false ? d : c;
```

Also I note there is a separate bug here in the type printer: https://godbolt.org/z/5afcxnor7

We get a diagnostic: `error: cannot initialize a variable of type 'Z' with an lvalue of type 'const ConstIntArray1' (aka 'const const int[1]')`. We can drop that redundant extra const, because otherwise it does not round trip to that doubly qualified type anyway.

About the fix, I think it's at the wrong level and we shouldn't just be dropping the qualifiers like that, but it's been a while I implemented this functionality and I would need some time to think about it.

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


More information about the cfe-commits mailing list