Clang допускает доступ к элементу данных d из псевдонима
шаблона p, тогда как GCC и MSVC отклоняют его. Должно ли это быть
разрешено или нет? Что об этом говорит стандарт?
При непрямом доступе к d путем разрешения типа возвращаемого значения
функции шаблона q с помощью с помощью псевдонима шаблона p,
все компиляторы отвергают программу. Это ожидаемый результат?
Означает ли это, что Clang просто ошибается, принимая
первый случай (определяющий a::m)?
class a {
int d;
static const int m, n;
};
template
using p = decltype(T::d);
const int a::m = sizeof(p); // clang ok, gcc nope, msvc nope
template
auto q() -> p;
const int a::n = sizeof(q()); // all nope
Демо
Сообщение об ошибке GCC:
: In substitution of 'template using p = decltype (T::d)
[with T = a]':
:8:28: required from here
8 | const int a::m = sizeof(p);
| ^
:6:20: error: 'int a::d' is private within this context
6 | using p = decltype(T::d);
| ^
:2:9: note: declared private here
2 | int d;
| ^
Сообщение об ошибке MSVC:
(6): error C2248: 'a::d': cannot access private member declared in
class 'a'
(2): note: see declaration of 'a::d'
(1): note: see declaration of 'a'
(6): note: the template instantiation context (the oldest one first) is
(8): note: see reference to alias template instantiation 'p'
being compiled
(8): error C2938: 'p' : Failed to specialize alias template
Подробнее здесь: https://stackoverflow.com/questions/791 ... s-template
Можно ли получить доступ к частным членам с помощью внешнего шаблона псевдонима? ⇐ C++
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение