4

For some reason there is still lack of expected CTAD for std::initializer_list in clang:

std::initializer_list l{1,2,3}; // error in clang

Adding a user-defined guide like the following can fix the issue:

namespace std {
    template<class T> 
    initializer_list(const initializer_list<T>&) -> initializer_list<T>; 
} 

But is it allowed to add a user-defined guide for CTAD for std:: types?

OrenIshShalom
  • 5,974
  • 9
  • 37
  • 87
αλεχολυτ
  • 4,792
  • 1
  • 35
  • 71
  • 1
    Last time I checked, I got the impression that Clang is correct here, and `std::initializer_list l{1,2,3}; ` is not supposed to compile. Are you sure the standard allows it? – HolyBlackCat Aug 15 '20 at 09:36
  • @HolyBlackCat that's what my question about. – αλεχολυτ Aug 15 '20 at 09:44
  • Your question asks something different, whether it’s allowed to add ... – Daniel Aug 15 '20 at 11:00
  • @Dani yep. Now I see the difference. Thank you for pointing this out. – αλεχολυτ Aug 15 '20 at 11:03
  • @HolyBlackCat despite the standard conformance (if any), code like ´std::initializer_list l{1,2,3};´ I think it should be expected as valid for regular c++ developer. So if there is lack in standard then standard should be fixed. – αλεχολυτ Aug 15 '20 at 11:44
  • This is a Clang bug, not a problem in the standard: https://stackoverflow.com/a/63426926/5632316 – Oliv Aug 15 '20 at 14:12

1 Answers1

5

Adding a deduction guide to a standard library type is UB [namespace std]§4.4:

The behavior of a C++ program is undefined if it declares : [...]

  • a deduction guide for any standard library class template.
Oliv
  • 17,610
  • 1
  • 29
  • 72