Skip to content
Snippets Groups Projects
Commit 21305376 authored by Markus Blatt's avatar Markus Blatt
Browse files

Prevent copyconstruction of FieldVector from FieldVector with

different size!

[[Imported from SVN: r6371]]
parent 16e72805
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,7 @@
#include "exceptions.hh"
#include "array.hh"
#include "densevector.hh"
#include "static_assert.hh"
namespace Dune {
......@@ -87,6 +88,14 @@ namespace Dune {
_data[i] = x[i];
}
//! Constructor making vector with identical coordinates
template<class K1, int SIZE1>
explicit FieldVector (const FieldVector<K1,SIZE1> & x)
{
static_assert(SIZE1 == SIZE, "FieldVector in costructor has wrong size");
for (size_type i = 0; i<SIZE; i++)
_data[i] = x[i];
}
using Base::operator=;
// make this thing a vector
......
......@@ -60,3 +60,4 @@ tags
pathtest
TAGS
mpihelpertest2
testfconstruct
......@@ -43,6 +43,7 @@ TESTPROGS = \
testfassign_fail4 \
testfassign_fail5 \
testfassign_fail6 \
testfconstruct \
tuplestest_dune \
tuplestest_std \
tuplestest_tr1 \
......@@ -52,7 +53,7 @@ TESTPROGS = \
# which tests to run
COMPILE_XFAIL=$(DUNE_COMMON_BIN)/xfail-compile-tests
COMPILE_XFAIL_TESTS = genericiterator_compile_fail nullptr-test-fail static_assert_test_fail
COMPILE_XFAIL_TESTS = genericiterator_compile_fail nullptr-test-fail static_assert_test_fail testfconstruct_fail1 testfconstruct_fail2
compile_XFAIL:
for i in $(COMPILE_XFAIL_TESTS); do \
......@@ -200,6 +201,15 @@ testfassign_fail5_CPPFLAGS = $(AM_CPPFLAGS) -D_N=2 -D_M=2 -D_VALUES="1, 2"
testfassign_fail6_SOURCES = testfassign.cc
testfassign_fail6_CPPFLAGS = $(AM_CPPFLAGS) -D_N=2 -D_M=2 -D_VALUES="1, 2, nextRow, 2, 3, nextRow, 4, 5"
testfconstruct_SOURCES = testfconstruct.cc
testfconstruct_CPPFLAGS = $(AM_CPPFLAGS) -DFVSIZE=3
testfconstruct_fail1_SOURCES = testfconstruct.cc
testfconstruct_fail1_CPPFLAGS = $(AM_CPPFLAGS) -DFVSIZE=2
testfconstruct_fail2_SOURCES = testfconstruct.cc
testfconstruct_fail2_CPPFLAGS = $(AM_CPPFLAGS) -DFVSIZE=5
conversiontest_SOURCES = conversiontest.cc
sourcescheck_NOSOURCES = exprtmpl.cc timing.cc
......
// -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
// vi: set et ts=4 sw=2 sts=2:
#include <config.h>
#include <iostream>
#include <dune/common/fvector.hh>
#include <dune/common/fassign.hh>
using namespace Dune;
int main(int argc, char** argv) {
Dune::FieldVector<double,3> pos;
pos <<= 1, 0, 0;
Dune::FieldVector<float,FVSIZE> pos2(pos);
}
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