diff --git a/change_notes/2024-02-12-improve-a18-0-1.md b/change_notes/2024-02-12-improve-a18-0-1.md new file mode 100644 index 0000000000..a4a9613a45 --- /dev/null +++ b/change_notes/2024-02-12-improve-a18-0-1.md @@ -0,0 +1,2 @@ +- `A18-0-1` - `CLibraryFacilitiesNotAccessedThroughCPPLibraryHeaders.ql`: + - Fix issue #7 - improve query logic to only match on exact standard library names (e.g., now excludes sys/header.h type headers from the results as those are not C standard libraries). \ No newline at end of file diff --git a/cpp/autosar/src/rules/A18-0-1/CLibraryFacilitiesNotAccessedThroughCPPLibraryHeaders.ql b/cpp/autosar/src/rules/A18-0-1/CLibraryFacilitiesNotAccessedThroughCPPLibraryHeaders.ql index ada60f305d..5c4d9d580f 100644 --- a/cpp/autosar/src/rules/A18-0-1/CLibraryFacilitiesNotAccessedThroughCPPLibraryHeaders.ql +++ b/cpp/autosar/src/rules/A18-0-1/CLibraryFacilitiesNotAccessedThroughCPPLibraryHeaders.ql @@ -28,7 +28,7 @@ where * not use any of 'signal.h's facilities, for example. */ - filename = i.getIncludedFile().getBaseName() and + filename = i.getIncludeText().substring(1, i.getIncludeText().length() - 1) and filename in [ "assert.h", "ctype.h", "errno.h", "fenv.h", "float.h", "inttypes.h", "limits.h", "locale.h", "math.h", "setjmp.h", "signal.h", "stdarg.h", "stddef.h", "stdint.h", "stdio.h", "stdlib.h", diff --git a/cpp/autosar/test/rules/A18-0-1/CLibraryFacilitiesNotAccessedThroughCPPLibraryHeaders.expected b/cpp/autosar/test/rules/A18-0-1/CLibraryFacilitiesNotAccessedThroughCPPLibraryHeaders.expected index 3952555595..ff53ffd841 100644 --- a/cpp/autosar/test/rules/A18-0-1/CLibraryFacilitiesNotAccessedThroughCPPLibraryHeaders.expected +++ b/cpp/autosar/test/rules/A18-0-1/CLibraryFacilitiesNotAccessedThroughCPPLibraryHeaders.expected @@ -19,3 +19,4 @@ | test.cpp:19:1:19:18 | #include | C library "uchar.h" is included instead of the corresponding C++ library . | | test.cpp:20:1:20:18 | #include | C library "wchar.h" is included instead of the corresponding C++ library . | | test.cpp:21:1:21:19 | #include | C library "wctype.h" is included instead of the corresponding C++ library . | +| test.cpp:45:1:45:17 | #include "time.h" | C library "time.h" is included instead of the corresponding C++ library . | diff --git a/cpp/autosar/test/rules/A18-0-1/lib/example.h b/cpp/autosar/test/rules/A18-0-1/lib/example.h new file mode 100644 index 0000000000..001980b02f --- /dev/null +++ b/cpp/autosar/test/rules/A18-0-1/lib/example.h @@ -0,0 +1,4 @@ +#ifndef LIB_EXAMPLE_H_ +#define LIB_EXAMPLE_H_ + +#endif \ No newline at end of file diff --git a/cpp/autosar/test/rules/A18-0-1/test.cpp b/cpp/autosar/test/rules/A18-0-1/test.cpp index b095017685..579842ddab 100644 --- a/cpp/autosar/test/rules/A18-0-1/test.cpp +++ b/cpp/autosar/test/rules/A18-0-1/test.cpp @@ -39,4 +39,7 @@ #include // COMPLIANT #include // COMPLIANT #include // COMPLIANT -#include // COMPLIANT \ No newline at end of file +#include // COMPLIANT + +#include "lib/example.h" // COMPLIANT +#include "time.h" // NON_COMPLIANT \ No newline at end of file diff --git a/cpp/autosar/test/rules/A18-0-1/time.h b/cpp/autosar/test/rules/A18-0-1/time.h new file mode 100644 index 0000000000..ba58b95bbc --- /dev/null +++ b/cpp/autosar/test/rules/A18-0-1/time.h @@ -0,0 +1,4 @@ +#ifndef LIB_TIME_EXAMPLE_H_ +#define LIB_TIME_EXAMPLE_H_ +// may be a user lib or a std lib checked into a project +#endif \ No newline at end of file