[cfe-commits] r135222 - in /cfe/trunk: lib/Sema/SemaExpr.cpp test/SemaCXX/expressions.cpp
Douglas Gregor
dgregor at apple.com
Thu Jul 14 17:04:49 PDT 2011
On Jul 14, 2011, at 5:00 PM, Richard Trieu wrote:
> Author: rtrieu
> Date: Thu Jul 14 19:00:51 2011
> New Revision: 135222
>
> URL: http://llvm.org/viewvc/llvm-project?rev=135222&view=rev
> Log:
> Remove warnings of constant operands of logical operators from template instantiations. Upon instantiation of template, value-dependent parameters are replaced by equivalent literals, so code like:
>
> template<unsigned int A, unsigned int B> struct S {
> int foo() {
> int x = A && B;
> }
> }
>
> will not warn on A && B on every instantiation. This will still warn on other cases inside templates, which will be caught on checking the template definition.
>
> Modified:
> cfe/trunk/lib/Sema/SemaExpr.cpp
> cfe/trunk/test/SemaCXX/expressions.cpp
>
> Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=135222&r1=135221&r2=135222&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Jul 14 19:00:51 2011
> @@ -6528,8 +6528,8 @@
> // is a constant.
> if (lex.get()->getType()->isIntegerType() && !lex.get()->getType()->isBooleanType() &&
> rex.get()->getType()->isIntegerType() && !rex.get()->isValueDependent() &&
> - // Don't warn in macros.
> - !Loc.isMacroID()) {
> + // Don't warn in macros or template instantiations.
> + !Loc.isMacroID() && ActiveTemplateInstantiations.empty()) {
> // If the RHS can be constant folded, and if it constant folds to something
> // that isn't 0 or 1 (which indicate a potential logical operation that
> // happened to fold to true/false) then warn.
This really doesn't seem like the right check, because this suppresses this warning in *all* template instantiations, even if the constant value was actually written as a constant value (but the other operand was something dependent, suppressing the warning at template definition time). IMO, the right approach would be to suppress this warning when the constant value itself was instantiated from something... although that's rather trickier to implement.
- Doug
More information about the cfe-commits
mailing list