[libcxx-commits] [clang] [libcxx] [Clang] Implement CWG2137 (list-initialization from objects of the same type) (PR #94355)

Yuxuan Chen via libcxx-commits libcxx-commits at lists.llvm.org
Fri Aug 9 12:11:49 PDT 2024


yuxuanchen1997 wrote:

A noob question but I wanted to make sure that this patch actually intended to reject program like this one?
```
#include <type_traits>
#include <vector>

class K {
 public:
  template <class T>
  K(const std::vector<T>& v) {
    static_assert(!std::is_same<T, K>::value, "Error!");
  }
};

void foo(std::vector<K>& inputs) {
  auto v{inputs};
}
```
Compiler Explorer: https://godbolt.org/z/659Pao8j9
GCC has always rejected this program but MSVC and EDG both accepted. After this patch, clang also rejects. This is a little unintuitive and I don't know how the intention of [CWG2137](https://cplusplus.github.io/CWG/issues/2137.html) covered this. 

Just need confirmation that this is intended. 

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


More information about the libcxx-commits mailing list