Ошибка расширения пакета параметров шаблонаC++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Ошибка расширения пакета параметров шаблона

Сообщение Anonymous »

Давайте рассмотрим следующий пример исходного кода на C++:

Код: Выделить всё

template 
struct test {
template 
static consteval void make() {
}
};

int main() {
test::make();
}
Пакеты параметров нельзя размещать в начале объявления шаблона, а здесь beg_vals просто расширяет пакет (по крайней мере, так думал). Я думал, что эта программа действительна, хотя она не компилируется ни с gcc, ни с msvc.

Код: Выделить всё

gccСообщение об ошибке :
: In function 'int main()':
:9:46: error: no matching function for call to 'test::make()'
9 |     test::make();
|     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
:4:27: note: candidate: 'template static consteval void test::make() [with end ...beg_vals = {beg_vals ...}; begin end_val = end_val; begin = char; end = {int, float}]'
4 |     static consteval void make() {
|                           ^~~~
:4:27: note:   template argument deduction/substitution failed:
:9:46: error: conversion from 'float' to 'char' in a converted constant expression
9 |     test::make();
|     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
:9:46: error: could not convert '6.0e+0f' from 'float' to 'char'
9 |     test::make();
|     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
|                                              |
|                                              float
:9:46: error: wrong number of template arguments (3, should be 2)
:4:27: note: provided for 'template static consteval void test::make() [with end ...beg_vals = {beg_vals ...}; begin end_val = end_val; begin = char; end = {int, float}]'
4 |     static consteval void make() {
|                           ^~~~
Compiler returned: 1

Код: Выделить всё

msvcСообщение об ошибке :
example.cpp
(4): error C3547: template parameter 'end_val' cannot be used because it follows a template parameter pack and cannot be deduced from the function parameters of 'test::make'
(3): note: see declaration of 'end_val'
(4): note: the template instantiation context (the oldest one first) is
(2): note: while compiling class template 'test'
Compiler returned: 2
At the same time, the program is accepted by modern clang++.
godbolt, case 1
I continued my experiment swapping beginning... and end parameter in make():

Код: Выделить всё

template 
struct test {
template 
static consteval void make() {
}
};

int main() {
test::make();
}

Это заставило msvc принять код.

Код: Выделить всё

gccСообщение об ошибке 
изменилось, но он продолжал «ожидать два параметра шаблона» в make.
godbolt, случай 2
I я почти уверен, что gcc как минимум ошибается в своем сообщении об ошибке.
Мои вопросы:
  • Первый источник действителен?
  • Второй источник действителен? действительно?
  • Есть ли отчет об ошибке для gcc?
Дополнительно:
  • Похожий вопрос без принятого ответа и без порядка параметров шаблона с учетом: ссылка.
  • Отчет об ошибке с похожим сообщением ICE: ссылка.


Подробнее здесь: https://stackoverflow.com/questions/793 ... on-failure
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C++»