From 4e100d18fa168f13f17d2b272e2e750748112995 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20Rheinl=C3=A4nder?= Date: Mon, 20 Sep 2010 12:23:14 +0000 Subject: [PATCH] [msvc] Work around strange scoping and name mangling rules. 1. msvc creates different symbols for a variable declared in a namespace scope and (the same variable) in a class method scope. That is, // util.cpp namespace GiNaC { extern const ex _ex0; // [1] } // ex.h namespace GiNaC { class ex { public: bool is_zero() { extern const ex _ex0; // mangled name of _ex0 is different that of [1] } }; } 2. The mangled names for cv-qualified and cv-unqualified versions of a type are different (which violates the requirements stated in [basic.type.qualifier]) These msvc's "features" cause linking failures due to unresolved external symbols. Solution: 1. Declare variables (_ex0) in the GiNaC namespace scope (for msvc only). 2. Add corresponding cv-qualifier(s). --- ginac/ex.h | 12 +++++++++++- ginac/parser/parse_binop_rhs.cpp | 2 +- ginac/parser/parser.cpp | 3 +-- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/ginac/ex.h b/ginac/ex.h index f0e6db51..d7bbf6df 100644 --- a/ginac/ex.h +++ b/ginac/ex.h @@ -32,6 +32,11 @@ #include namespace GiNaC { +#ifdef _MSC_VER + // MSVC produces a different symbol for _ex0 when it is declared inside + // ex::is_zero() than when it is declared at top level as follows + extern const ex _ex0; +#endif /** Helper class to initialize the library. There must be one static object * of this class in every object file that makes use of our flyweights in @@ -204,7 +209,12 @@ public: // comparison int compare(const ex & other) const; bool is_equal(const ex & other) const; - bool is_zero() const { extern const ex _ex0; return is_equal(_ex0); } + bool is_zero() const { +#ifndef _MSC_VER + extern const ex _ex0; +#endif + return is_equal(_ex0); + } bool is_zero_matrix() const; // symmetry diff --git a/ginac/parser/parse_binop_rhs.cpp b/ginac/parser/parse_binop_rhs.cpp index f114c2e2..a0ca4cd3 100644 --- a/ginac/parser/parse_binop_rhs.cpp +++ b/ginac/parser/parse_binop_rhs.cpp @@ -114,7 +114,7 @@ ex parser::parse_binop_rhs(int expr_prec, ex& lhs) } } -extern numeric* _num_1_p; +extern const numeric* _num_1_p; static ex make_minus_expr(const exvector& args) { diff --git a/ginac/parser/parser.cpp b/ginac/parser/parser.cpp index 06743833..16eed69d 100644 --- a/ginac/parser/parser.cpp +++ b/ginac/parser/parser.cpp @@ -82,8 +82,7 @@ ex parser::parse_paren_expr() return e; } -extern numeric* _num_1_p; -extern ex _ex0; +extern const ex _ex0; /// unary_expr: [+-] expression ex parser::parse_unary_expr() -- 2.44.0