Fehler bei der Erweiterung des VorlagenparameterpaketsC++

Programme in C++. Entwicklerforum
Anonymous
 Fehler bei der Erweiterung des Vorlagenparameterpakets

Post by Anonymous »

Betrachten wir die folgende Beispielquelle in C++:

Code: Select all

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

int main() {
test::make();
}
Parameterpakete können nicht am Anfang einer Vorlagendeklaration platziert werden, aber hier beg_vals erweitern Sie einfach ein Paket (zumindest gedacht). Ich dachte, dieses Programm sei gültig, obwohl es weder mit gcc noch mit msvc kompiliert werden kann.

Code: Select all

gccFehlermeldung von 
:

Code: Select all

: 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

Code: Select all

msvcFehlermeldung von 
:

Code: Select all

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
Gleichzeitig wird das Programm von modernem Clang++ akzeptiert.
Godbolt, Fall 1
Ich setzte mein Experiment fort und vertauschte die Parameter begin... und end in make():

Code: Select all

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

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

Dies veranlasste msvc, den Code zu akzeptieren.

Code: Select all

gccDie Fehlermeldung von 
hat sich geändert, aber es wurden weiterhin „zwei Vorlagenparameter erwartet“ in make.
Godbolt, Fall 2
I Ich bin mir ziemlich sicher, dass gcc zumindest in seiner Fehlermeldung falsch liegt.
Meine Fragen sind:
  • Ist die erste Quelle gültig?
  • Ist die zweite Quelle gültig? gültig?
  • Gibt es einen Fehlerbericht für gcc?
Zusätzlich:
  • Ähnliche Frage ohne akzeptierte Antwort und ohne Vorlageparameter. Reihenfolge unter Berücksichtigung: Link.
  • Fehlerbericht mit ähnlicher ICE-Meldung: Link.

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post