Skip to content

Commit 340c802

Browse files
authored
Merge pull request github#1965 from jbj/bitfield-template
C++: Ignore templates in AmbiguouslySignedBitField.ql
2 parents 6b78314 + 34a5368 commit 340c802

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

cpp/ql/src/Likely Bugs/AmbiguouslySignedBitField.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ where
2828
not bf.getType().hasName("BOOL") and
2929
// If this is true, then there cannot be unsigned sign extension or overflow.
3030
not bf.getDeclaredNumBits() = bf.getType().getSize() * 8 and
31-
not bf.isAnonymous()
31+
not bf.isAnonymous() and
32+
not bf.isFromUninstantiatedTemplate(_)
3233
select bf,
3334
"Bit field " + bf.getName() + " of type " + bf.getUnderlyingType().getName() +
3435
" should have explicitly unsigned integral, explicitly signed integral, or enumeration type."

cpp/ql/test/query-tests/Likely Bugs/AmbiguouslySignedBitField/test.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,10 @@ struct {
2525
myEnum nosignenum : 2;
2626
const myEnum constnosignenum : 2;
2727
};
28+
29+
template<typename T>
30+
struct TemplateWithBitfield {
31+
T templatesign : 2; // GOOD
32+
};
33+
34+
TemplateWithBitfield<signed int> twb;

0 commit comments

Comments
 (0)