Skip to content
Snippets Groups Projects
Commit 98bac513 authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

Explicitly disable gcc's dangling ref. warning

These functions cannot return a dangling reference.
parent 60a6b559
No related branches found
No related tags found
No related merge requests found
......@@ -21,6 +21,7 @@
#include <typeinfo>
#include <utility>
#include "CompilerWorkarounds.h"
#include "Error.h"
namespace BaseLib
......@@ -110,8 +111,8 @@ void insertIfKeyUniqueElseError(Map& map, Key const& key, Value&& value,
//! otherwise an \c error_message is printed and the program is aborted.
//! Cf. also the const overload below.
template <typename Map, typename Key>
typename Map::mapped_type& getOrError(Map& map, Key const& key,
std::string const& error_message)
OGS_NO_DANGLING typename Map::mapped_type& getOrError(
Map& map, Key const& key, std::string const& error_message)
{
auto it = map.find(key);
if (it == map.end())
......@@ -131,8 +132,8 @@ typename Map::mapped_type& getOrError(Map& map, Key const& key,
}
//! \overload
template <typename Map, typename Key>
typename Map::mapped_type const& getOrError(Map const& map, Key const& key,
std::string const& error_message)
OGS_NO_DANGLING typename Map::mapped_type const& getOrError(
Map const& map, Key const& key, std::string const& error_message)
{
auto it = map.find(key);
if (it == map.end())
......@@ -155,7 +156,7 @@ typename Map::mapped_type const& getOrError(Map const& map, Key const& key,
//! the \c predicate exists;
//! otherwise an \c error_message is printed and the program is aborted.
template <typename Container, typename Predicate>
typename Container::value_type const& getIfOrError(
OGS_NO_DANGLING typename Container::value_type const& getIfOrError(
Container const& container,
Predicate&& predicate,
std::string const& error_message)
......
/**
* \file
* \copyright
* Copyright (c) 2012-2024, OpenGeoSys Community (http://www.opengeosys.org)
* Distributed under a Modified BSD License.
* See accompanying file LICENSE.txt or
* http://www.opengeosys.org/project/license
*/
#pragma once
#if defined(__GNUC__) && __GNUC__ == 14
#define OGS_NO_DANGLING [[gnu::no_dangling]]
#else
#define OGS_NO_DANGLING
#endif
......@@ -13,6 +13,7 @@
#include <memory>
#include <vector>
#include "BaseLib/CompilerWorkarounds.h"
#include "GeoLib/Grid.h"
#include "MathLib/Point3dWithID.h"
#include "MeshGeoToolsLib/SearchAllNodes.h"
......@@ -87,10 +88,11 @@ public:
* Returns a (possibly new) mesh node searcher for the mesh.
* A new one will be created, if it does not already exists.
*/
static MeshNodeSearcher const& getMeshNodeSearcher(
MeshLib::Mesh const& mesh,
std::unique_ptr<MeshGeoToolsLib::SearchLength>&&
search_length_algorithm);
OGS_NO_DANGLING
static MeshNodeSearcher const&
getMeshNodeSearcher(MeshLib::Mesh const& mesh,
std::unique_ptr<MeshGeoToolsLib::SearchLength>&&
search_length_algorithm);
private:
MeshLib::Mesh const& _mesh;
......
......@@ -12,6 +12,7 @@
#include <vector>
#include "BaseLib/CompilerWorkarounds.h"
#include "BaseLib/ConfigTree.h"
#include "BaseLib/Error.h"
#include "Parameter.h"
......@@ -98,10 +99,11 @@ Parameter<ParameterDataType>* findParameterOptional(
///
/// \see The documentation of the other findParameter() function.
template <typename ParameterDataType>
Parameter<ParameterDataType>& findParameter(
OGS_NO_DANGLING Parameter<ParameterDataType>& findParameter(
std::string const& parameter_name,
std::vector<std::unique_ptr<ParameterBase>> const& parameters,
int const num_components, MeshLib::Mesh const* const mesh = nullptr)
int const num_components,
MeshLib::Mesh const* const mesh = nullptr)
{
auto* parameter = findParameterOptional<ParameterDataType>(
parameter_name, parameters, num_components, mesh);
......@@ -130,10 +132,12 @@ Parameter<ParameterDataType>& findParameter(
/// and return a reference to that parameter. Additionally it checks for the
/// type of the found parameter.
template <typename ParameterDataType>
Parameter<ParameterDataType>& findParameter(
BaseLib::ConfigTree const& process_config, std::string const& tag,
OGS_NO_DANGLING Parameter<ParameterDataType>& findParameter(
BaseLib::ConfigTree const& process_config,
std::string const& tag,
std::vector<std::unique_ptr<ParameterBase>> const& parameters,
int const num_components, MeshLib::Mesh const* const mesh = nullptr)
int const num_components,
MeshLib::Mesh const* const mesh = nullptr)
{
// Find parameter name in process config.
//! \ogs_file_special
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment