build: (fixes #730) add compiler workaround for ostream& operator<<(ostream&, nullptr_t)

This commit is contained in:
Gabriel Ferreira
2022-08-30 20:30:07 +00:00
committed by Tommaso Pecorella
parent 27c8ef63db
commit 2dd6f858c0
3 changed files with 74 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
#ifndef OSTREAM_OPERATOR_NULLPTR_H
#define OSTREAM_OPERATOR_NULLPTR_H
#include <iostream>
#include <cstddef>
namespace std
{
inline std::ostream &operator<< (std::ostream &os, std::nullptr_t ptr)
{
return os << "nullptr"; //whatever you want nullptr to show up as in the console
}
}
#endif //OSTREAM_OPERATOR_NULLPTR_H

View File

@@ -0,0 +1,50 @@
# Copyright (c) 2022 Universidade de Brasília
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License version 2 as published by the Free
# Software Foundation;
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
# Place, Suite 330, Boston, MA 02111-1307 USA
#
# Author: Gabriel Ferreira <gabrielcarvfer@gmail.com>
include(CheckCXXSourceCompiles)
# Clang 6, 7 and 8 shipped with incomplete C++17 features and do not handle
# ostream& operator<<(ostream& os, nullptr_t ptr)
# https://gitlab.com/nsnam/ns-3-dev/-/issues/730
check_cxx_source_compiles(
"
#include <iostream>
#include <cstddef>
inline std::ostream& operator << (std::ostream& os, std::nullptr_t ptr)
{
return os << \"nullptr\"; //whatever you want nullptr to show up as in the console
}
int main()
{
std::ostream os(NULL);
os << std::nullptr_t();
return 0;
}
"
MISSING_OSTREAM_NULLPTR_OPERATOR
)
if(${MISSING_OSTREAM_NULLPTR_OPERATOR})
message(
${HIGHLIGHTED_STATUS}
"Using compiler workaround: compiling in \"ostream& operator<<(ostream&, nullptr_t)\""
)
add_definitions(
-include
${CMAKE_CURRENT_SOURCE_DIR}/build-support/compiler-workarounds/ostream-operator-nullptr.h
)
endif()

View File

@@ -495,6 +495,15 @@ macro(process_options)
)
endif()
# Honor CMAKE_CXX_STANDARD in check_cxx_source_compiles
# https://cmake.org/cmake/help/latest/policy/CMP0067.html
cmake_policy(SET CMP0066 NEW)
cmake_policy(SET CMP0067 NEW)
# After setting the correct CXX version, we can proceed to check for compiler
# workarounds
include(build-support/custom-modules/ns3-compiler-workarounds.cmake)
if(${NS3_DES_METRICS})
add_definitions(-DENABLE_DES_METRICS)
endif()