[cfe-users] False positive -Wcomma with static_cast of dependent expression
Hello list, The following code generates one false positive of the -Wcomma warning: (tested with clang trunk via Matt Godbolt's Compiler Explorer) template void foo() { (void)42, 0;// ok static_cast(42), 0; // ok (void)T{}, 0; // ok static_cast(T{}), 0; // false positive } The warning ignores comma expressions where the LHS is a CastExpr with a CastKind of CK_ToVoid, but the expression static_cast(T{}) has a CastKind of CK_Dependent (confirmed with Compiler Explorer's AST view). I came across this when trying to do the "expander trick" without a fold expression or C-style cast, as in https://stackoverflow.com/a/30563282/1639256 Thanks Mat ___ cfe-users mailing list cfe-users@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users
Re: [cfe-users] dynmaic_cast in uninstantiated function templates
On Wed, 24 Oct 2018 at 02:06, Olaf wrote: > > the code below compiles on gcc and icc, but not on clang with the error: > > source_file.cpp:14:16: error: 'B' is an incomplete type > if (auto b = dynamic_cast(a)) > > However fn is an uninstantiated function template. > Is this a glitch in clang or is clang the only one right here? > > class B; > > template > void fn(A* a, T& x) > { > dynamic_cast(a); > } All three compilers are correct here, as far as the standard is concerned. The code is ill-formed, but implementations are not required to diagnose this kind of error. There is no type T that could produce a well-formed instantiation of fn. ___ cfe-users mailing list cfe-users@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-users