@@ -35,13 +35,25 @@ predicate isTypeZeroInitializable(Type t) {
3535 t .getUnderlyingType ( ) instanceof ArrayType
3636}
3737
38- from Variable v
38+ from Variable v , string msg
3939where
4040 not isExcluded ( v , ConstPackage:: variableMissingConstexprQuery ( ) ) and
4141 v .hasDefinition ( ) and
4242 not v .isConstexpr ( ) and
4343 not v instanceof Parameter and
4444 not v .isAffectedByMacro ( ) and
45+ (
46+ not v instanceof MemberVariable
47+ or
48+ // In case member functions are left un-instantiated, it is possible
49+ // the member variable could be modified in them.
50+ // Hence, don't raise an alert in case this member variable's class
51+ // has a member function that doesn't have a definition.
52+ not exists ( MemberFunction mf |
53+ mf .getDeclaringType ( ) = v .getDeclaringType ( ) and
54+ mf .isFromUninstantiatedTemplate ( _)
55+ )
56+ ) and
4557 isLiteralType ( v .getType ( ) ) and
4658 // Unfortunately, `isConstant` is not sufficient here because it doesn't include calls to
4759 // constexpr constructors, and does not take into account zero initialization
6678 // Exclude variables in uninstantiated templates, as they may be incomplete
6779 not v .isFromUninstantiatedTemplate ( _) and
6880 // Exclude compiler generated variables, which are not user controllable
69- not v .isCompilerGenerated ( )
70- select v , "Variable '" + v .getName ( ) + "' could be marked 'constexpr'."
81+ not v .isCompilerGenerated ( ) and
82+ if v instanceof MemberVariable and not v .isStatic ( ) then msg = " and static." else msg = "."
83+ select v , "Variable '" + v .getName ( ) + "' could be marked 'constexpr'" + msg
0 commit comments