DirectXShaderCompiler icon indicating copy to clipboard operation
DirectXShaderCompiler copied to clipboard

Template error (non-type template argument of type '<dependent type>' must have an integral or enumeration type) with a particular use of the ternary/conditional operator in a template instantiation

Open KStocky opened this issue 1 year ago • 0 comments

Description This code fails to compile https://godbolt.org/z/G98xG5xja. It would appear that if we are using a ternary operator to evaluate a template argument, AND the conditional part of that ternary operator uses a template instantiation, THEN that template instantiation must appear in one of the two following expressions.

To demonstrate that this is possibly the issue, here are some succeeding and failing cases:

  1. No template instantiations are involved. This succeeds: https://godbolt.org/z/bx5Y8qqaM
  2. One of the return expressions of the ternary operator is also a template but is different from the one used in the condition expression. This fails: https://godbolt.org/z/bWTbn7n7v
  3. The condition and one of the return expressions contain the same template instantiation. This succeeds: https://godbolt.org/z/xExchWbjd
  4. One of the return expressions has the same template instantiation but in a more complex way. This succeeds (and is my workaround): https://godbolt.org/z/46TsEzvqd

Steps to Reproduce https://godbolt.org/z/G98xG5xja https://godbolt.org/z/bWTbn7n7v

Steps to Workaround https://godbolt.org/z/bYeKsWv7Y

Actual Behavior We get "non-type template argument of type '' must have an integral or enumeration type" when the expression should be valid.

Environment

  • DXC version 1.7.2308.12
  • Host Operating System Windows 10 Pro 22H2

KStocky avatar Feb 12 '24 08:02 KStocky