-
Notifications
You must be signed in to change notification settings - Fork 5
Update example to C++20 and use modules #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
alejandro-alvarez-sonarsource
wants to merge
11
commits into
sonarsource-cfamily-examples:main
from
alejandro-alvarez-sonarsource:aa/modules
Closed
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
cd3fe33
Point to my SC project
alejandro-alvarez-sonarsource e886cb1
Enable modules analysis
alejandro-alvarez-sonarsource 00c6a6b
WIP
alejandro-alvarez-sonarsource b8c61f6
Add some issues that are triggered if the module is visible
alejandro-alvarez-sonarsource 05f38db
Use Ninja
alejandro-alvarez-sonarsource 47761f4
Install ninja
alejandro-alvarez-sonarsource d20c752
Install clang 18
alejandro-alvarez-sonarsource 92c1599
Build
alejandro-alvarez-sonarsource de385bd
Update sonar-project.properties
alejandro-alvarez-sonarsource 9305241
Merge branch 'sonarsource-cfamily-examples:main' into aa/modules
alejandro-alvarez-sonarsource b7b059c
Update sonar-project.properties
alejandro-alvarez-sonarsource File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
---|---|---|
@@ -1,8 +1,16 @@ | ||
cmake_minimum_required(VERSION 3.9) | ||
project(sonar_scanner_example) | ||
cmake_minimum_required(VERSION 3.30) | ||
|
||
project(sonar_scanner_example LANGUAGES CXX) | ||
|
||
set(CMAKE_CXX_STANDARD 20) | ||
set(CMAKE_CXX_STANDARD_REQUIRED ON) | ||
set(CMAKE_CXX_EXTENSIONS OFF) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON) | ||
|
||
add_executable(sonar_scanner_example src/main.cpp) | ||
|
||
target_sources(sonar_scanner_example | ||
PRIVATE | ||
FILE_SET CXX_MODULES FILES src/args.cppm | ||
) |
This file contains hidden or 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 |
---|---|---|
@@ -1,12 +1,17 @@ | ||
|
||
sonar.projectKey=sonarsource-cfamily-examples_linux-cmake-compdb-gh-actions-sc | ||
sonar.organization=sonarsource-cfamily-examples | ||
sonar.projectKey=alejandro-alvarez-sonarsource_linux-cmake-compdb-gh-actions-sc | ||
sonar.organization=alejandro-alvarez-sonarsource | ||
sonar.projectName=linux-cmake-compdb-gh-actions-sc | ||
sonar.projectVersion=1.0-SNAPSHOT | ||
sonar.projectVersion=2.0-MODULES | ||
|
||
# ===================================================== | ||
# Properties that will be shared amongst all modules | ||
# ===================================================== | ||
|
||
# SQ standard properties | ||
sonar.sources=src | ||
# Enable C++20 modules | ||
# TODO: Remove internal | ||
sonar.cfamily.internal.enableModules=true | ||
# TODO: Remove | ||
sonar.cfamily.analysisCache.mode=internal.off |
This file contains hidden or 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,40 @@ | ||
module; | ||
#include <iostream> | ||
#include <string_view> | ||
#include <variant> | ||
|
||
export module args; | ||
|
||
export namespace args { | ||
|
||
enum class Error { | ||
Ok, | ||
TooLong, | ||
TooManyArgs, | ||
NullPtr, | ||
}; | ||
|
||
std::variant<std::string_view, Error> process_args(int argc, char *argv[]) { | ||
int num = argc - 1; | ||
|
||
if (num == 0) { | ||
std::cout << "No arguments provided\n"; | ||
} else if (num == 0) { // intentional mistake | ||
std::cout << "1 argument provided\n"; | ||
} else if (num == 2) { | ||
std::cout << "2 arguments provided\n"; | ||
} else { | ||
std::cout << num << " arguments provided\n"; | ||
} | ||
if (argv != 0) { | ||
std::cout << "argv not null\n"; | ||
; // intentional extra-semicolon | ||
} | ||
|
||
if (argv == nullptr) { | ||
return std::string_view(*argv); // intentional nullptr dereference | ||
} | ||
|
||
return std::string_view(argv[0]); | ||
} | ||
} // namespace args |
This file contains hidden or 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 |
---|---|---|
@@ -1,26 +1,22 @@ | ||
#include <iostream> | ||
#include <variant> | ||
|
||
using namespace std; | ||
import args; | ||
|
||
int main(int argc, char* argv[]) { | ||
int num = argc - 1; | ||
using namespace std; | ||
|
||
if (num == 0) { | ||
cout << "No arguments provided\n"; | ||
} else if (num == 0) { // intentional mistake | ||
cout << "1 argument provided\n"; | ||
} else if (num == 2) { | ||
cout << "2 arguments provided\n"; | ||
} else { | ||
cout << num << " arguments provided\n"; | ||
} | ||
if (argv != 0) { | ||
cout << "argv not null\n";; // intentional extra-semicolon | ||
} | ||
if (argv == nullptr) { | ||
return **argv; // intentional nullptr dereference | ||
int main(int argc, char *argv[]) { | ||
auto get_proc_name = args::process_args(argc, argv); | ||
if (std::holds_alternative<args::Error>(get_proc_name)) { | ||
switch (std::get<args::Error>(get_proc_name)) { | ||
case args::Error::TooLong: | ||
std::cout << "Proc name too long\n"; | ||
return 1; | ||
} | ||
return 0; | ||
} | ||
|
||
auto &&value = std::get<std::string_view>(get_proc_name); | ||
std::cout << value << '\n'; | ||
return 0; | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to remember to remove it.