summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2025-01-20 17:40:29 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2025-01-20 17:40:29 +0100
commit3438b4d3eb272c301e28af7cb72c6d2adb0e6597 (patch)
treef3e53448cfd126c563a528d2c775845cc2951e12
parentfe0f5eba353b268336ebc775decf36b37ef805aa (diff)
Add typed c/c++ compiler flags for -Wconversion, -Wshadow and -Wextra.
-rw-r--r--src/ctor.h6
-rw-r--r--src/tools.cc107
2 files changed, 113 insertions, 0 deletions
diff --git a/src/ctor.h b/src/ctor.h
index 0892364..3c0b303 100644
--- a/src/ctor.h
+++ b/src/ctor.h
@@ -90,6 +90,9 @@ enum class cxx_opt
output, // -o
debug, // -g
warn_all, // -Wall
+ warn_conversion, // -Wconversion
+ warn_shadow, // -Wshadow
+ warn_extra, // -Wextra
warnings_as_errors, // -Werror
generate_dep_tree, // -MMD
no_link, // -c
@@ -108,6 +111,9 @@ enum class c_opt
output, // -o
debug, // -g
warn_all, // -Wall
+ warn_conversion, // -Wconversion
+ warn_shadow, // -Wshadow
+ warn_extra, // -Wextra
warnings_as_errors, // -Werror
generate_dep_tree, // -MMD
no_link, // -c
diff --git a/src/tools.cc b/src/tools.cc
index eb98265..db13855 100644
--- a/src/tools.cc
+++ b/src/tools.cc
@@ -20,6 +20,9 @@ std::ostream& operator<<(std::ostream& stream, const ctor::c_opt& opt)
case ctor::c_opt::output: stream << "ctor::c_opt::output"; break;
case ctor::c_opt::debug: stream << "ctor::c_opt::debug"; break;
case ctor::c_opt::warn_all: stream << "ctor::c_opt::warn_all"; break;
+ case ctor::c_opt::warn_conversion: stream << "ctor::c_opt::warn_conversion"; break;
+ case ctor::c_opt::warn_shadow: stream << "ctor::c_opt::warn_shadow"; break;
+ case ctor::c_opt::warn_extra: stream << "ctor::c_opt::warn_extra"; break;
case ctor::c_opt::warnings_as_errors: stream << "ctor::c_opt::warnings_as_errors"; break;
case ctor::c_opt::generate_dep_tree: stream << "ctor::c_opt::generate_dep_tree"; break;
case ctor::c_opt::no_link: stream << "ctor::c_opt::no_link"; break;
@@ -43,6 +46,9 @@ std::ostream& operator<<(std::ostream& stream, const ctor::cxx_opt& opt)
case ctor::cxx_opt::output: stream << "ctor::cxx_opt::output"; break;
case ctor::cxx_opt::debug: stream << "ctor::cxx_opt::debug"; break;
case ctor::cxx_opt::warn_all: stream << "ctor::cxx_opt::warn_all"; break;
+ case ctor::cxx_opt::warn_conversion: stream << "ctor::cxx_opt::warn_conversion"; break;
+ case ctor::cxx_opt::warn_shadow: stream << "ctor::cxx_opt::warn_shadow"; break;
+ case ctor::cxx_opt::warn_extra: stream << "ctor::cxx_opt::warn_extra"; break;
case ctor::cxx_opt::warnings_as_errors: stream << "ctor::cxx_opt::warnings_as_errors"; break;
case ctor::cxx_opt::generate_dep_tree: stream << "ctor::cxx_opt::generate_dep_tree"; break;
case ctor::cxx_opt::no_link: stream << "ctor::cxx_opt::no_link"; break;
@@ -247,6 +253,48 @@ ctor::c_flag c_option(const std::string& flag)
return { ctor::c_opt::include_path, path };
}
+ if(flag.starts_with("-std="))
+ {
+ std::string std = flag.substr(5);
+ return { ctor::c_opt::c_std, std };
+ }
+
+ if(flag.starts_with("-O"))
+ {
+ std::string opt = flag.substr(2, 1);
+ return { ctor::c_opt::optimization, opt };
+ }
+
+ if(flag.starts_with("-Wall"))
+ {
+ return { ctor::c_opt::warn_all };
+ }
+
+ if(flag.starts_with("-Wconversion"))
+ {
+ return { ctor::c_opt::warn_conversion};
+ }
+
+ if(flag.starts_with("-Wshadow"))
+ {
+ return { ctor::c_opt::warn_shadow};
+ }
+
+ if(flag.starts_with("-Wextra"))
+ {
+ return { ctor::c_opt::warn_extra};
+ }
+
+ if(flag.starts_with("-Werror"))
+ {
+ return { ctor::c_opt::warnings_as_errors };
+ }
+
+ if(flag.starts_with("-g"))
+ {
+ return { ctor::c_opt::debug };
+ }
+
if(flag.starts_with("-D"))
{
std::string def = flag.substr(2);
@@ -272,6 +320,48 @@ ctor::cxx_flag cxx_option(const std::string& flag)
return { ctor::cxx_opt::include_path, path };
}
+ if(flag.starts_with("-std="))
+ {
+ std::string std = flag.substr(5);
+ return { ctor::cxx_opt::cpp_std, std };
+ }
+
+ if(flag.starts_with("-O"))
+ {
+ std::string opt = flag.substr(2, 1);
+ return { ctor::cxx_opt::optimization, opt };
+ }
+
+ if(flag.starts_with("-Wall"))
+ {
+ return { ctor::cxx_opt::warn_all };
+ }
+
+ if(flag.starts_with("-Werror"))
+ {
+ return { ctor::cxx_opt::warnings_as_errors };
+ }
+
+ if(flag.starts_with("-Wconversion"))
+ {
+ return { ctor::cxx_opt::warn_conversion};
+ }
+
+ if(flag.starts_with("-Wshadow"))
+ {
+ return { ctor::cxx_opt::warn_shadow};
+ }
+
+ if(flag.starts_with("-Wextra"))
+ {
+ return { ctor::cxx_opt::warn_extra};
+ }
+
+ if(flag.starts_with("-g"))
+ {
+ return { ctor::cxx_opt::debug };
+ }
+
if(flag.starts_with("-D"))
{
std::string def = flag.substr(2);
@@ -298,6 +388,11 @@ ctor::ld_flag ld_option(const std::string& flag)
return { ctor::ld_opt::library_path, path };
}
+ if(flag.starts_with("-pthread"))
+ {
+ return { ctor::ld_opt::threads };
+ }
+
return { ctor::ld_opt::custom, flag };
}
@@ -317,6 +412,12 @@ std::vector<std::string> cxx_option(ctor::cxx_opt opt, const std::string& arg,
return {"-g"};
case ctor::cxx_opt::warn_all:
return {"-Wall"};
+ case ctor::cxx_opt::warn_conversion:
+ return {"-Wconversion"};
+ case ctor::cxx_opt::warn_shadow:
+ return {"-Wshadow"};
+ case ctor::cxx_opt::warn_extra:
+ return {"-Wextra"};
case ctor::cxx_opt::warnings_as_errors:
return {"-Werror"};
case ctor::cxx_opt::generate_dep_tree:
@@ -358,6 +459,12 @@ std::vector<std::string> c_option(ctor::c_opt opt, const std::string& arg,
return {"-g"};
case ctor::c_opt::warn_all:
return {"-Wall"};
+ case ctor::c_opt::warn_conversion:
+ return {"-Wconversion"};
+ case ctor::c_opt::warn_shadow:
+ return {"-Wshadow"};
+ case ctor::c_opt::warn_extra:
+ return {"-Wextra"};
case ctor::c_opt::warnings_as_errors:
return {"-Werror"};
case ctor::c_opt::generate_dep_tree: