Skip to content

Commit

Permalink
clang: support cxx20_flag and cxx23_flag (#43438)
Browse files Browse the repository at this point in the history
* clang: support cxx20_flag and cxx23_flag

* clang: coverage test cxx{}_flag and c{}_flag additions
  • Loading branch information
wdconinc committed May 12, 2024
1 parent 12e3665 commit f8f01c3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
25 changes: 24 additions & 1 deletion lib/spack/spack/compilers/clang.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ def verbose_flag(self):

openmp_flag = "-fopenmp"

# C++ flags based on CMake Modules/Compiler/Clang.cmake

@property
def cxx11_flag(self):
if self.real_version < Version("3.3"):
Expand All @@ -120,6 +122,24 @@ def cxx17_flag(self):

return "-std=c++17"

@property
def cxx20_flag(self):
if self.real_version < Version("5.0"):
raise UnsupportedCompilerFlag(self, "the C++20 standard", "cxx20_flag", "< 5.0")
elif self.real_version < Version("11.0"):
return "-std=c++2a"
else:
return "-std=c++20"

@property
def cxx23_flag(self):
if self.real_version < Version("12.0"):
raise UnsupportedCompilerFlag(self, "the C++23 standard", "cxx23_flag", "< 12.0")
elif self.real_version < Version("17.0"):
return "-std=c++2b"
else:
return "-std=c++23"

@property
def c99_flag(self):
return "-std=c99"
Expand All @@ -142,7 +162,10 @@ def c17_flag(self):
def c23_flag(self):
if self.real_version < Version("9.0"):
raise UnsupportedCompilerFlag(self, "the C23 standard", "c23_flag", "< 9.0")
return "-std=c2x"
elif self.real_version < Version("18.0"):
return "-std=c2x"
else:
return "-std=c23"

@property
def cc_pic_flag(self):
Expand Down
9 changes: 9 additions & 0 deletions lib/spack/spack/test/compilers/basics.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,18 @@ def test_clang_flags():
unsupported_flag_test("cxx17_flag", "clang@3.4")
supported_flag_test("cxx17_flag", "-std=c++1z", "clang@3.5")
supported_flag_test("cxx17_flag", "-std=c++17", "clang@5.0")
unsupported_flag_test("cxx20_flag", "clang@4.0")
supported_flag_test("cxx20_flag", "-std=c++2a", "clang@5.0")
supported_flag_test("cxx20_flag", "-std=c++20", "clang@11.0")
unsupported_flag_test("cxx23_flag", "clang@11.0")
supported_flag_test("cxx23_flag", "-std=c++2b", "clang@12.0")
supported_flag_test("cxx23_flag", "-std=c++23", "clang@17.0")
supported_flag_test("c99_flag", "-std=c99", "clang@3.3")
unsupported_flag_test("c11_flag", "clang@2.0")
supported_flag_test("c11_flag", "-std=c11", "clang@6.1.0")
unsupported_flag_test("c23_flag", "clang@8.0")
supported_flag_test("c23_flag", "-std=c2x", "clang@9.0")
supported_flag_test("c23_flag", "-std=c23", "clang@18.0")
supported_flag_test("cc_pic_flag", "-fPIC", "clang@3.3")
supported_flag_test("cxx_pic_flag", "-fPIC", "clang@3.3")
supported_flag_test("f77_pic_flag", "-fPIC", "clang@3.3")
Expand Down

0 comments on commit f8f01c3

Please sign in to comment.