Closed
Description
Bugzilla Link | 42854 |
Version | trunk |
OS | All |
CC | @DougGregor,@zygoloid |
Extended Description
If you activate -Wconsumed
using a pragma rather than on the command line, it seemingly doesn't trigger the consumed analysis pass.
Given the following example code:
#pragma clang diagnostic error "-Wconsumed"
struct [[clang::consumable(unconsumed)]] Linear {
[[clang::return_typestate(unconsumed)]]
Linear() {}
[[clang::callable_when(consumed)]]
~Linear() {}
};
void a() {
Linear l;
}
Compiling the code as is, without passing -Wconsumed
on the command line, I get no warnings or errors.
The pragma does enable -Wconsumed
warnings about malformed declarations: if I e.g. comment out the consumable attribute on Linear, I get:
error: consumed analysis attribute is attached to member of class 'Linear' which isn't marked as consumable [-Werror,-Wconsumed]
However, without commenting anything out, I expect this diagnostic from a()
:
error: invalid invocation of method '~Linear' on object 'l' while it is in the 'unconsumed' state [-Werror,-Wconsumed]
I get this if and only if I pass -Wconsumed
on the command line.
Tested on Compiler Explorer's "x86-64 clang (trunk)".