From 225cc0c87449c6c1baaa88e694c223560e353308 Mon Sep 17 00:00:00 2001 From: Daniel Arndt Date: Thu, 14 Feb 2019 22:50:50 +0100 Subject: [PATCH] Delete the disallowed functions instead --- include/deal.II/lac/linear_operator.h | 64 +++++++-------------------- tests/lac/linear_operator_18.cc | 55 ----------------------- tests/lac/linear_operator_18.output | 6 --- 3 files changed, 16 insertions(+), 109 deletions(-) delete mode 100644 tests/lac/linear_operator_18.cc delete mode 100644 tests/lac/linear_operator_18.output diff --git a/include/deal.II/lac/linear_operator.h b/include/deal.II/lac/linear_operator.h index 64dff9a099..b8e118fe11 100644 --- a/include/deal.II/lac/linear_operator.h +++ b/include/deal.II/lac/linear_operator.h @@ -1477,9 +1477,7 @@ linear_operator(const LinearOperator &operator_exemplar, // // Ensure that we never capture a reference to a temporary by accident. -// This ensures that instead of silently allowing a "stack use after free", -// we at least bail out with a runtime error message that is slightly more -// understandable. +// to avoid "stack use after free". // template < @@ -1491,13 +1489,7 @@ template < typename = typename std::enable_if::value>::type> LinearOperator -linear_operator(const OperatorExemplar &, Matrix &&) -{ - Assert(false, - ExcMessage( - "You are trying to construct a linear operator from a temporary " - "matrix object.")); -} +linear_operator(const OperatorExemplar &, Matrix &&) = delete; template < typename Range = Vector, @@ -1506,15 +1498,12 @@ template < typename OperatorExemplar, typename Matrix, typename = typename std::enable_if< - !std::is_lvalue_reference::value>::type> + !std::is_lvalue_reference::value>::type, + typename = typename std::enable_if< + !std::is_same>::value>::type> LinearOperator -linear_operator(OperatorExemplar &&, const Matrix &) -{ - Assert(false, - ExcMessage( - "You are trying to construct a linear operator with a temporary " - "operator_exemplar object.")); -} +linear_operator(OperatorExemplar &&, const Matrix &) = delete; template < typename Range = Vector, @@ -1525,16 +1514,12 @@ template < typename = typename std::enable_if::value>::type, typename = typename std::enable_if< - !std::is_lvalue_reference::value>::type> + !std::is_lvalue_reference::value>::type, + typename = typename std::enable_if< + !std::is_same>::value>::type> LinearOperator -linear_operator(OperatorExemplar &&, Matrix &&) -{ - Assert(false, - ExcMessage( - "You are trying to construct a linear operator from a temporary " - "matrix object.")); -} - +linear_operator(OperatorExemplar &&, Matrix &&) = delete; template < typename Range = Vector, @@ -1544,13 +1529,8 @@ template < typename = typename std::enable_if::value>::type> LinearOperator -linear_operator(const LinearOperator &, Matrix &&) -{ - Assert(false, - ExcMessage( - "You are trying to construct a linear operator from a temporary " - "matrix object.")); -} +linear_operator(const LinearOperator &, + Matrix &&) = delete; template < typename Range = Vector, @@ -1560,13 +1540,7 @@ template < typename = typename std::enable_if::value>::type> LinearOperator -linear_operator(Matrix &&) -{ - Assert(false, - ExcMessage( - "You are trying to construct a linear operator from a temporary " - "matrix object.")); -} +linear_operator(Matrix &&) = delete; template inverse_operator(const LinearOperator &, Solver &, - Preconditioner &&) -{ - Assert(false, - ExcMessage( - "You are trying to construct an inverse operator with a temporary " - "preconditioner object.")); -} + Preconditioner &&) = delete; #endif // DOXYGEN diff --git a/tests/lac/linear_operator_18.cc b/tests/lac/linear_operator_18.cc deleted file mode 100644 index 08fbfb1801..0000000000 --- a/tests/lac/linear_operator_18.cc +++ /dev/null @@ -1,55 +0,0 @@ -// --------------------------------------------------------------------- -// -// Copyright (C) 2015 - 2018 by the deal.II authors -// -// This file is part of the deal.II library. -// -// The deal.II library is free software; you can use it, redistribute -// it, and/or modify it under the terms of the GNU Lesser General -// Public License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// The full text of the license can be found in the file LICENSE.md at -// the top level directory of deal.II. -// -// --------------------------------------------------------------------- - -// Test that we cannot accidentally create a linear operator from a -// temporary object - -#include -#include -#include - -#include "../tests.h" - -#define CATCH(call) \ - try \ - { \ - call; \ - deallog << "Error: Something went wrong!" << std::endl; \ - } \ - catch (ExceptionBase & e) \ - { \ - deallog << e.get_exc_name() << std::endl; \ - } - -using namespace dealii; - -int -main() -{ - initlog(); - deal_II_exceptions::disable_abort_on_exception(); - - SparseMatrix A; - const auto op_A = linear_operator(A); - - CATCH(linear_operator(SparseMatrix())) - CATCH(linear_operator(SparseMatrix(), A)) - CATCH(linear_operator(A, SparseMatrix())) - CATCH(linear_operator(SparseMatrix(), SparseMatrix())) - - SolverControl solver_control; - SolverCG> solver(solver_control); - CATCH(inverse_operator(op_A, solver, SparseMatrix())) -} diff --git a/tests/lac/linear_operator_18.output b/tests/lac/linear_operator_18.output deleted file mode 100644 index 8aad5753bc..0000000000 --- a/tests/lac/linear_operator_18.output +++ /dev/null @@ -1,6 +0,0 @@ - -DEAL::ExcMessage( "You are trying to construct a linear operator from a temporary " "matrix object.") -DEAL::ExcMessage( "You are trying to construct a linear operator with a temporary " "operator_exemplar object.") -DEAL::ExcMessage( "You are trying to construct a linear operator from a temporary " "matrix object.") -DEAL::ExcMessage( "You are trying to construct a linear operator from a temporary " "matrix object.") -DEAL::ExcMessage( "You are trying to construct an inverse operator with a temporary " "preconditioner object.") -- 2.39.5