admin管理员组文章数量:1410724
Here is the test code:
#include <type_traits>
enum class ShaderType:unsigned{
Vertex = 0,
Fragment = 1,
};
template<ShaderType type> struct ShaderTypeHolder{
static constexpr ShaderType m_type = type;
};
struct VertexData{
int vertex;
};
struct FragmentData{
int fragment;
};
template <typename DataT>
static constexpr bool ShaderTypeMatchData(ShaderType type)
{
bool result = false;
switch(type){
case ShaderType::Vertex:
{
result = std::is_same_v<DataT, VertexData>;
break;
}
case ShaderType::Fragment:
{
result = std::is_same_v<DataT, FragmentData>;
break;
}
default:
break;
}
return result;
}
template<class DataT> constexpr void VisitData(ShaderType type, DataT data){
VisitBaseOnShaderType(
[&data](auto holder) {
if constexpr (holder.m_type == ShaderType::Vertex &&
ShaderTypeMatchData<DataT>(holder.m_type))
{
int val = data.vertex;
}
},
type
);
}
template<class visitor> constexpr void VisitBaseOnShaderType(visitor&& visitorFunc, ShaderType shader_type){
switch (shader_type){
case ShaderType::Vertex:
{
constexpr ShaderType type = ShaderType::Vertex;
visitorFunc(ShaderTypeHolder<type>());
break;
}
case ShaderType::Fragment:
{
constexpr ShaderType type = ShaderType::Fragment;
visitorFunc(ShaderTypeHolder<type>());
break;
}
default:
break;
}
}
int main(){
VertexData vertex;
FragmentData fragment;
VisitData(ShaderType::Vertex, vertex);
VisitData(ShaderType::Fragment, fragment);
return 0;
}
with gcc11, compile is ok, but with clang14, compile is failed. g++ test.cpp -std=c++17 clang++ test.cpp -std=c++17
here is the error log:
error: no member named 'vertex' in 'FragmentData'
int val = data.vertex;
~~~~ ^
test.cpp: note: in instantiation of function template specialization 'VisitData<FragmentData>' requested here
VisitData(ShaderType::Fragment, fragment);
Is this caused by code or is it a clang bug?
本文标签: cconstexpr if with function parameter error with clanggcc is okStack Overflow
版权声明:本文标题:c++ - constexpr if with function parameter error with clang, gcc is ok - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744806552a2626180.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论