Skip to content

Commit 34a5368

Browse files
committed
C++: Ignore templates in AmbiguouslySignedBitField
If it's possible that the type is not fully resolved, it's better to avoid giving an alert. This fixes a FP in https://github.com/heremaps/flatdata.
1 parent 0ed0951 commit 34a5368

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
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/AmbiguouslySignedBitField.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@
33
| test.cpp:20:8:20:18 | nosignshort | Bit field nosignshort of type short should have explicitly unsigned integral, explicitly signed integral, or enumeration type. |
44
| test.cpp:21:18:21:30 | nosigntypedef | Bit field nosigntypedef of type int should have explicitly unsigned integral, explicitly signed integral, or enumeration type. |
55
| test.cpp:23:15:23:25 | nosignconst | Bit field nosignconst of type const int should have explicitly unsigned integral, explicitly signed integral, or enumeration type. |
6-
| test.cpp:31:5:31:16 | templatesign | Bit field templatesign of type T should have explicitly unsigned integral, explicitly signed integral, or enumeration type. |

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct {
2828

2929
template<typename T>
3030
struct TemplateWithBitfield {
31-
T templatesign : 2; // GOOD [FALSE POSITIVE]
31+
T templatesign : 2; // GOOD
3232
};
3333

3434
TemplateWithBitfield<signed int> twb;

0 commit comments

Comments
 (0)