From 07cb7ab7b231dac7222c9a684b57c11190e54cb8 Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Mon, 6 May 2024 15:32:47 -0400 Subject: [PATCH 1/5] Request C++17 by default, add fallback flag for now --- make/compiler_flags | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/make/compiler_flags b/make/compiler_flags index 5a3a703f07f..407d5932082 100644 --- a/make/compiler_flags +++ b/make/compiler_flags @@ -123,8 +123,12 @@ CPPFLAGS_SUNDIALS ?= -DNO_FPRINTF_OUTPUT $(CPPFLAGS_OPTIM_SUNDIALS) $(CXXFLAGS_F #CPPFLAGS_GTEST ?= -## setup compiler flags -CXXFLAGS_LANG ?= -std=c++1y +ifeq ($(STAN_USE_CPP14),) + CXXFLAGS_LANG ?= -std=c++17 +else + $(warning "Because STAN_USE_CPP14 is set C++14 standard is requested. This will not be possible in the next release!") + CXXFLAGS_LANG ?= -std=c++1y +endif #CXXFLAGS_BOOST ?= CXXFLAGS_SUNDIALS ?= -pipe $(CXXFLAGS_OPTIM_SUNDIALS) $(CPPFLAGS_FLTO_SUNDIALS) #CXXFLAGS_GTEST From 9b7155865768f7987be2bbae93978bfbc689555a Mon Sep 17 00:00:00 2001 From: Steve Bronder Date: Thu, 16 May 2024 12:50:19 -0400 Subject: [PATCH 2/5] update to use logic to check compiler version for c++17 compatability --- .../contributor_help_pages/developer_doc.md | 2 +- make/compiler_flags | 26 ++++++++++++++++--- make/libraries | 4 +-- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/doxygen/contributor_help_pages/developer_doc.md b/doxygen/contributor_help_pages/developer_doc.md index 0961a5ba9c3..687eb1b157d 100644 --- a/doxygen/contributor_help_pages/developer_doc.md +++ b/doxygen/contributor_help_pages/developer_doc.md @@ -184,7 +184,7 @@ These are the more common make flags that could be set: These are the rest of the variables that can be set: - C++ compiler flags - - `CXXFLAGS_LANG`: sets the language. Currently defaults to `-std=c++1y` + - `CXXFLAGS_LANG`: sets the language. Currently defaults to `-std=c++17` - `CXXFLAGS_WARNINGS`: compiler options to squash compiler warnings - `CXXFLAGS_BOOST`: Boost-specific compiler flags - `CXXFLAGS_EIGEN`: Eigen-specific compiler flags diff --git a/make/compiler_flags b/make/compiler_flags index 407d5932082..73268a95204 100644 --- a/make/compiler_flags +++ b/make/compiler_flags @@ -70,7 +70,6 @@ CXX_VERSION := $(shell $(CXX) -dumpfullversion -dumpversion 2>&1) CXX_MAJOR := $(word 1,$(subst ., ,$(CXX_VERSION))) CXX_MINOR := $(word 2,$(subst ., ,$(CXX_VERSION))) - ################################################################################ # Set optional compiler flags for performance # @@ -122,13 +121,34 @@ CPPFLAGS_BOOST ?= -DBOOST_DISABLE_ASSERTS CPPFLAGS_SUNDIALS ?= -DNO_FPRINTF_OUTPUT $(CPPFLAGS_OPTIM_SUNDIALS) $(CXXFLAGS_FLTO_SUNDIALS) #CPPFLAGS_GTEST ?= - -ifeq ($(STAN_USE_CPP14),) +ifeq ($(CXX_TYPE), gcc) + GCC_GE_73 := $(shell [ $(CXX_MAJOR) -gt 7 -o \( $(CXX_MAJOR) -eq 7 -a $(CXX_MINOR) -ge 1 \) ] && echo true) + ifeq ($(GCC_GE_73),true) + CXXFLAGS_LANG ?= -std=c++17 + CXXFLAGS_STANDARD ?= c++17 + endif +else ifeq ($(CXX_TYPE), clang) + CLANG_GE_5 := $(shell [ $(CXX_MAJOR) -gt 5 -o \( $(CXX_MAJOR) -eq 5 -a $(CXX_MINOR) -ge 0 \) ] && echo true) + ifeq ($(CLANG_GE_5),true) + CXXFLAGS_LANG ?= -std=c++17 + CXXFLAGS_STANDARD ?= c++17 + endif +else ifeq ($(CXX_TYPE), mingw32-gcc) + MINGW_GE_50 := $(shell [ $(CXX_MAJOR) -gt 5 -o \( $(CXX_MAJOR) -eq 5 -a $(CXX_MINOR) -ge 0 \) ] && echo true) + ifeq ($(MINGW_GE_50),true) + CXXFLAGS_LANG ?= -std=c++17 + CXXFLAGS_STANDARD ?= c++17 + endif +else ifeq ($(STAN_USE_CPP14),) CXXFLAGS_LANG ?= -std=c++17 + CXXFLAGS_STANDARD ?= c++17 else $(warning "Because STAN_USE_CPP14 is set C++14 standard is requested. This will not be possible in the next release!") CXXFLAGS_LANG ?= -std=c++1y + CXXFLAGS_STANDARD ?= c++1y endif + + #CXXFLAGS_BOOST ?= CXXFLAGS_SUNDIALS ?= -pipe $(CXXFLAGS_OPTIM_SUNDIALS) $(CPPFLAGS_FLTO_SUNDIALS) #CXXFLAGS_GTEST diff --git a/make/libraries b/make/libraries index f6beafcda46..e2b347d8388 100644 --- a/make/libraries +++ b/make/libraries @@ -176,11 +176,11 @@ endif $(TBB_BIN)/tbb.def: $(TBB_BIN)/tbb-make-check @mkdir -p $(TBB_BIN) touch $(TBB_BIN)/version_$(notdir $(TBB)) - tbb_root="$(TBB_RELATIVE_PATH)" WINARM64="$(WINARM64)" CXX="$(CXX)" CC="$(TBB_CC)" LDFLAGS='$(LDFLAGS_TBB)' '$(MAKE)' -C "$(TBB_BIN)" -r -f "$(TBB_ABSOLUTE_PATH)/build/Makefile.tbb" compiler=$(TBB_CXX_TYPE) cfg=release stdver=c++1y CXXFLAGS="$(TBB_CXXFLAGS)" + tbb_root="$(TBB_RELATIVE_PATH)" WINARM64="$(WINARM64)" CXX="$(CXX)" CC="$(TBB_CC)" LDFLAGS='$(LDFLAGS_TBB)' '$(MAKE)' -C "$(TBB_BIN)" -r -f "$(TBB_ABSOLUTE_PATH)/build/Makefile.tbb" compiler=$(TBB_CXX_TYPE) cfg=release stdver=$(CXXFLAGS_STANDARD) CXXFLAGS="$(TBB_CXXFLAGS)" $(TBB_BIN)/tbbmalloc.def: $(TBB_BIN)/tbb-make-check @mkdir -p $(TBB_BIN) - tbb_root="$(TBB_RELATIVE_PATH)" WINARM64="$(WINARM64)" CXX="$(CXX)" CC="$(TBB_CC)" LDFLAGS='$(LDFLAGS_TBB)' '$(MAKE)' -C "$(TBB_BIN)" -r -f "$(TBB_ABSOLUTE_PATH)/build/Makefile.tbbmalloc" compiler=$(TBB_CXX_TYPE) cfg=release stdver=c++1y malloc CXXFLAGS="$(TBB_CXXFLAGS)" + tbb_root="$(TBB_RELATIVE_PATH)" WINARM64="$(WINARM64)" CXX="$(CXX)" CC="$(TBB_CC)" LDFLAGS='$(LDFLAGS_TBB)' '$(MAKE)' -C "$(TBB_BIN)" -r -f "$(TBB_ABSOLUTE_PATH)/build/Makefile.tbbmalloc" compiler=$(TBB_CXX_TYPE) cfg=release stdver=$(CXXFLAGS_STANDARD) malloc CXXFLAGS="$(TBB_CXXFLAGS)" $(TBB_BIN)/libtbb.dylib: $(TBB_BIN)/tbb.def $(TBB_BIN)/libtbbmalloc.dylib: $(TBB_BIN)/tbbmalloc.def From e43440c6719791db8e79d520ff720ef4efc60d67 Mon Sep 17 00:00:00 2001 From: Steve Bronder Date: Thu, 16 May 2024 16:50:40 -0400 Subject: [PATCH 3/5] update to use logic to check compiler version for c++17 compatability --- make/compiler_flags | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/make/compiler_flags b/make/compiler_flags index 73268a95204..98cd0daf3c3 100644 --- a/make/compiler_flags +++ b/make/compiler_flags @@ -120,35 +120,45 @@ INC_GTEST ?= -I $(GTEST)/include -I $(GTEST) CPPFLAGS_BOOST ?= -DBOOST_DISABLE_ASSERTS CPPFLAGS_SUNDIALS ?= -DNO_FPRINTF_OUTPUT $(CPPFLAGS_OPTIM_SUNDIALS) $(CXXFLAGS_FLTO_SUNDIALS) #CPPFLAGS_GTEST ?= - +HAS_CXX17 := false ifeq ($(CXX_TYPE), gcc) GCC_GE_73 := $(shell [ $(CXX_MAJOR) -gt 7 -o \( $(CXX_MAJOR) -eq 7 -a $(CXX_MINOR) -ge 1 \) ] && echo true) ifeq ($(GCC_GE_73),true) CXXFLAGS_LANG ?= -std=c++17 CXXFLAGS_STANDARD ?= c++17 + HAS_CXX17 := true endif else ifeq ($(CXX_TYPE), clang) CLANG_GE_5 := $(shell [ $(CXX_MAJOR) -gt 5 -o \( $(CXX_MAJOR) -eq 5 -a $(CXX_MINOR) -ge 0 \) ] && echo true) ifeq ($(CLANG_GE_5),true) CXXFLAGS_LANG ?= -std=c++17 CXXFLAGS_STANDARD ?= c++17 + HAS_CXX17 := true endif else ifeq ($(CXX_TYPE), mingw32-gcc) MINGW_GE_50 := $(shell [ $(CXX_MAJOR) -gt 5 -o \( $(CXX_MAJOR) -eq 5 -a $(CXX_MINOR) -ge 0 \) ] && echo true) ifeq ($(MINGW_GE_50),true) CXXFLAGS_LANG ?= -std=c++17 CXXFLAGS_STANDARD ?= c++17 + HAS_CXX17 := true endif else ifeq ($(STAN_USE_CPP14),) CXXFLAGS_LANG ?= -std=c++17 CXXFLAGS_STANDARD ?= c++17 + HAS_CXX17 := true else $(warning "Because STAN_USE_CPP14 is set C++14 standard is requested. This will not be possible in the next release!") CXXFLAGS_LANG ?= -std=c++1y CXXFLAGS_STANDARD ?= c++1y + HAS_CXX17 := true endif - +ifeq ($(HAS_CXX17), false) + $(warning "Because STAN_USE_CPP14 is set C++14 standard is requested. This will not be possible in the next release!") + CXXFLAGS_LANG ?= -std=c++1y + CXXFLAGS_STANDARD ?= c++1y + HAS_CXX17 := true +endif #CXXFLAGS_BOOST ?= CXXFLAGS_SUNDIALS ?= -pipe $(CXXFLAGS_OPTIM_SUNDIALS) $(CPPFLAGS_FLTO_SUNDIALS) #CXXFLAGS_GTEST From a4bc3cd6014da62aeddcd34dc79783f06fcda320 Mon Sep 17 00:00:00 2001 From: Steve Bronder Date: Thu, 16 May 2024 16:51:14 -0400 Subject: [PATCH 4/5] fix type where HAS_CXX17 should be false for ifeq failure --- make/compiler_flags | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/make/compiler_flags b/make/compiler_flags index 98cd0daf3c3..6d8a530c08c 100644 --- a/make/compiler_flags +++ b/make/compiler_flags @@ -150,7 +150,7 @@ else $(warning "Because STAN_USE_CPP14 is set C++14 standard is requested. This will not be possible in the next release!") CXXFLAGS_LANG ?= -std=c++1y CXXFLAGS_STANDARD ?= c++1y - HAS_CXX17 := true + HAS_CXX17 := false endif ifeq ($(HAS_CXX17), false) From 16337a12be78dbb31625f4cfe3075f6987d75477 Mon Sep 17 00:00:00 2001 From: Steve Bronder Date: Fri, 17 May 2024 15:44:56 -0400 Subject: [PATCH 5/5] cleanup make definitions for c++17 --- make/compiler_flags | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/make/compiler_flags b/make/compiler_flags index 6d8a530c08c..3ef7c046b56 100644 --- a/make/compiler_flags +++ b/make/compiler_flags @@ -120,44 +120,31 @@ INC_GTEST ?= -I $(GTEST)/include -I $(GTEST) CPPFLAGS_BOOST ?= -DBOOST_DISABLE_ASSERTS CPPFLAGS_SUNDIALS ?= -DNO_FPRINTF_OUTPUT $(CPPFLAGS_OPTIM_SUNDIALS) $(CXXFLAGS_FLTO_SUNDIALS) #CPPFLAGS_GTEST ?= -HAS_CXX17 := false +STAN_HAS_CXX17 ?= false ifeq ($(CXX_TYPE), gcc) GCC_GE_73 := $(shell [ $(CXX_MAJOR) -gt 7 -o \( $(CXX_MAJOR) -eq 7 -a $(CXX_MINOR) -ge 1 \) ] && echo true) ifeq ($(GCC_GE_73),true) - CXXFLAGS_LANG ?= -std=c++17 - CXXFLAGS_STANDARD ?= c++17 - HAS_CXX17 := true + STAN_HAS_CXX17 := true endif else ifeq ($(CXX_TYPE), clang) CLANG_GE_5 := $(shell [ $(CXX_MAJOR) -gt 5 -o \( $(CXX_MAJOR) -eq 5 -a $(CXX_MINOR) -ge 0 \) ] && echo true) ifeq ($(CLANG_GE_5),true) - CXXFLAGS_LANG ?= -std=c++17 - CXXFLAGS_STANDARD ?= c++17 - HAS_CXX17 := true + STAN_HAS_CXX17 := true endif else ifeq ($(CXX_TYPE), mingw32-gcc) MINGW_GE_50 := $(shell [ $(CXX_MAJOR) -gt 5 -o \( $(CXX_MAJOR) -eq 5 -a $(CXX_MINOR) -ge 0 \) ] && echo true) ifeq ($(MINGW_GE_50),true) - CXXFLAGS_LANG ?= -std=c++17 - CXXFLAGS_STANDARD ?= c++17 - HAS_CXX17 := true + STAN_HAS_CXX17 := true endif -else ifeq ($(STAN_USE_CPP14),) +endif + +ifeq ($(STAN_HAS_CXX17), true) CXXFLAGS_LANG ?= -std=c++17 CXXFLAGS_STANDARD ?= c++17 - HAS_CXX17 := true else - $(warning "Because STAN_USE_CPP14 is set C++14 standard is requested. This will not be possible in the next release!") - CXXFLAGS_LANG ?= -std=c++1y - CXXFLAGS_STANDARD ?= c++1y - HAS_CXX17 := false -endif - -ifeq ($(HAS_CXX17), false) - $(warning "Because STAN_USE_CPP14 is set C++14 standard is requested. This will not be possible in the next release!") + $(warning "Stan cannot detect if your compiler has the C++17 standard. If it does, please set STAN_HAS_CXX17=true in your make/local file. C++17 support is mandatory in the next release of Stan. Defaulting to C++14") CXXFLAGS_LANG ?= -std=c++1y CXXFLAGS_STANDARD ?= c++1y - HAS_CXX17 := true endif #CXXFLAGS_BOOST ?= CXXFLAGS_SUNDIALS ?= -pipe $(CXXFLAGS_OPTIM_SUNDIALS) $(CPPFLAGS_FLTO_SUNDIALS)