llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.21k stars 11.64k forks source link

Implement CWG2685: Aggregate CTAD, string, and brace elision #95383

Open hokein opened 3 months ago

hokein commented 3 months ago

see https://cplusplus.github.io/CWG/issues/2685.html

llvmbot commented 3 months ago

@llvm/issue-subscribers-clang-frontend

Author: Haojian Wu (hokein)

see https://cplusplus.github.io/CWG/issues/2685.html
zyn0217 commented 3 months ago

I think that has already been implemented? See the test in https://github.com/llvm/llvm-project/commit/3475116e2c37a2c8a69658b36c02871c322da008

hokein commented 3 months ago

I didn't see any related implementation for the rule an array type with a dependent array element type and x_i is a string literal in clang.

Yeah, clang accepts the testcase, but the result seems incorrect:

template <class T>
struct A {
  T ar[4];
};
A a = {"foo"};

Here, the template argument T is deduced as const char*, but I believe the expected result is char.

Clang also accepts the following case, I think it should be rejected as brace elision is not considered for string literals:

template <class T>
struct A {
  T ar[4];
};
A a = {"a", "b", "c", "d"};
zyn0217 commented 3 months ago

It's interesting to note that all compilers accept the case https://godbolt.org/z/WhPo939f7 (MSVC is seemingly unavailable at the moment) I reread the CWG issue and now I changed my mind that we probably should reject such a case. And sorry for merging that PR recklessly - I'll revert it shortly.

Edit: https://github.com/llvm/llvm-project/pull/95389

zyn0217 commented 3 months ago

(Assigned it to myself in the hope that I would be able to look into it in the next few days.)