-
- Downloads
[release][matrixmarket][ODR] Give the name MatrixMarketImpl to the anonymous
namespace. This namespace was probably meant to mark implementation details. However it led to violations of the ODR (one definition rule), and to warnings about defined-but-unused functions (see below). To illustrate the problem consider the function template Dune::readMatrixMarket: template<typename T, typename A, int brows, int bcols> void readMatrixMarket(Dune::BCRSMatrix<Dune::FieldMatrix<T,brows,bcols>,A>& matrix, std::istream& istr) { // ... readSparseEntries(matrix, istr, entries, header, NumericWrapper<T>()); } The ODR states (§3.2/5): There can be more than one definition of a [...] non-static function template (14.5.6) [...] in a program provided that each definition appears in a different translation unit, and provided the definitions satisfy the following requirements. Given such an entity named D defined in more than one translation unit, then - each definition of D shall consist of the same sequence of tokens; and - in each definition of D, corresponding names, looked up according to 3.4, shall refer to an entity defined within the definition of D, or shall refer to the same entity, after overload resolution (13.3) and after matching of partial template specialization (14.8.3), except that a name can refer to a const object with internal or no linkage if the object has the same literal type in all definitions of D, and the object is initialized with a constant expression (5.19), and the value (but not the address) of the object is used, and the object has the same value in all definitions of D; and [...] This is violated by e.g. both readSparseEntries, which is defined in the anonymous namespace. Since it is not defined within readMatrixMarket, it must refer to the same entity in all translation units. However, its name is effectively Dune::<unique>::readSparseEntries, where <unique> is unique to each translation unit, and thus it effectively refers to a different entity in each translation unit, and the program is ill-formed as soon as move than one translation unit does #include <dune/istl/matrixmarket.hh>. The warnings by g++-4.9 looked like this: ====================================================================== g++ -std=c++11 -DHAVE_CONFIG_H -I. -I../../.. -pthread -I/home/joe/Projekte/pdelab-2.4/dune-common -I/home/joe/Projekte/pdelab-2.4/dune-common -I../../.. -I/usr/lib/openmpi/include -I/usr/lib/openmpi/include/openmpi -pthread -DMPIPP_H -DENABLE_MPI=1 -g -O3 -Wall -MT matrixmarkettest-matrixmarkettest.o -MD -MP -MF .deps/matrixmarkettest-matrixmarkettest.Tpo -c -o matrixmarkettest-matrixmarkettest.o `test -f 'matrixmarkettest.cc' || echo './'`matrixmarkettest.cc [...] In file included from matrixmarkettest.cc:11:0: ../../../dune/istl/matrixmarket.hh:501:10: warning: ‘void Dune::{anonymous}::readNextLine(std::istream&, std::ostringstream&, Dune::{anonymous}::LineType&)’ defined but not used [-Wunused-function] void readNextLine(std::istream& file, std::ostringstream&, LineType& type) ^ In file included from matrixmarkettest.cc:11:0: ../../../dune/istl/matrixmarket.hh:601:19: warning: ‘std::istream& Dune::{anonymous}::operator>>(std::istream&, Dune::{anonymous}::NumericWrapper<Dune::{anonymous}::PatternDummy>&)’ defined but not used [-Wunused-function] std::istream& operator>>(std::istream& is, NumericWrapper<PatternDummy>& num) ^ ======================================================================
Please register or sign in to comment