-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Experimental support for setting the '__cplusplus' macro
`__cplusplus` is a macro defined by the compiler specifying if C++ is used to compile the file and which C++ standard is used. `__cplusplus` typically is not passed on the compiler command line as defined value, but set internally by the preprocessor while processing a file. Thus, DWYU does not know about it when performing the processing to resolve preprocessor statements. To work around this, DWYU we can set `__cplusplus` based on a heuristic. This heuristic is for now a best guess and thus the feature is experimental without any guarantee for stability.
- Loading branch information
Showing
19 changed files
with
254 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
cc_library( | ||
name = "cpp_lib", | ||
srcs = ["cpp_lib.cpp"], | ||
hdrs = ["cpp_lib.h"], | ||
) | ||
|
||
cc_library( | ||
name = "use_specific_cpp_standard", | ||
hdrs = ["use_specific_cpp_standard.h"], | ||
copts = ["-std=c++17"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
**Beware, this is an experimental feature which has not yet a stable behavior!** | ||
|
||
`__cplusplus` is a macro defined by the compiler specifying if C++ is used to compile the file and which C++ standard is used. | ||
`__cplusplus` typically is not passed on the compiler command line as defined value, but set internally by the preprocessor while processing a file. | ||
Thus, DWYU does not know about it when performing the processing to resolve preprocessor statements. | ||
To work around this, DWYU we can set `__cplusplus` based on a heuristic. | ||
|
||
Executing <br> | ||
`bazel build --aspects=//:aspect.bzl%dwyu_set_cplusplus --output_groups=dwyu //set_cpp_standard:cpp_lib` <br> | ||
showcases that DWYU can process `__cplusplus` based preprocessor statements with a heuristic. | ||
|
||
Executing <br> | ||
`bazel build --aspects=//:aspect.bzl%dwyu_set_cplusplus --output_groups=dwyu //set_cpp_standard:use_specific_cpp_standard` <br> | ||
showcases that checking for a specific C++ standard works as long as the compiler command specifies the desired C++ standard. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include "set_cpp_standard/cpp_lib.h" | ||
|
||
void someFunction() { | ||
// Do something | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#ifndef __cplusplus | ||
|
||
#include "not/existing/dep.h" | ||
|
||
#endif | ||
|
||
void someFunction(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#if __cplusplus != 201703 | ||
|
||
#include "not/existing/dep.h" | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.