Contexpr, если с ошибкой параметра функции с Clang, GCC в порядкеC++

Программы на C++. Форум разработчиков
Ответить
Anonymous
 Contexpr, если с ошибкой параметра функции с Clang, GCC в порядке

Сообщение Anonymous »

Вот тестовый код: < /p>

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

#include 
enum class ShaderType:unsigned{
Vertex = 0,
Fragment = 1,
};

template struct ShaderTypeHolder{
static constexpr ShaderType m_type = type;
};

struct VertexData{
int vertex;
};

struct FragmentData{
int fragment;
};

template 
static constexpr bool ShaderTypeMatchData(ShaderType type)
{
bool result = false;
switch(type){
case ShaderType::Vertex:
{
result = std::is_same_v;
break;
}
case ShaderType::Fragment:
{
result = std::is_same_v;
break;
}
default:
break;
}

return result;
}

template constexpr void VisitData(ShaderType type, DataT data){
VisitBaseOnShaderType(
[&data](auto holder) {
if constexpr (holder.m_type == ShaderType::Vertex &&
ShaderTypeMatchData(holder.m_type))
{
int val = data.vertex;
}
},
type
);
}
template constexpr void VisitBaseOnShaderType(visitor&& visitorFunc, ShaderType shader_type){
switch (shader_type){
case ShaderType::Vertex:
{
constexpr ShaderType type = ShaderType::Vertex;
visitorFunc(ShaderTypeHolder());
break;
}
case ShaderType::Fragment:
{
constexpr ShaderType type = ShaderType::Fragment;
visitorFunc(ShaderTypeHolder());
break;
}
default:
break;
}
}

int main(){
VertexData vertex;
FragmentData fragment;
VisitData(ShaderType::Vertex, vertex);
VisitData(ShaderType::Fragment, fragment);
return 0;
}
< /code>
с GCC11, компиляция в порядке, но с Clang14, компиляция не стерж.error: no member named 'vertex' in 'FragmentData'
int val = data.vertex;
~~~~ ^
test.cpp: note: in instantiation of function template specialization 'VisitData' requested here
VisitData(ShaderType::Fragment, fragment);
это вызвано кодом или это ошибка Clang?

Подробнее здесь: https://stackoverflow.com/questions/795 ... -gcc-is-ok
Ответить

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

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

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

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

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