Number: 2139
Title: lib/neatogen/sparsegraph.h defines an overloaded function that is extern "C"
Submitter: Michael Shields
Date: Tue Feb 15 16:36:16 2011
Subsys: Build/Installation
Version: 2.26.3
System: *-*-
Severity: minor
Problem:
When compiled with C++, the max() and min() functions in lib/neatogen/sparsegraph.h can cause a build error. This is because the functions are overloaded, but because it is inside an extern "C" block, name mangling is disabled and so the int and double versions are in conflict. Even though they are declared inline, they still have external linkage because the "inline" keyword is only a hint.
Comments:
[erg] Applying the patch induces hundreds of errors like

stringfwd.h:48: error: template with C linkage

which makes sense, since #include <algorithm> is being opened within an extern "C" block.

The easiest thing to do is remove the definitions, since they are relics anyway.
Fix:


--- a/lib/neatogen/sparsegraph.h
+++ b/lib/neatogen/sparsegraph.h
@@ -37,31 +37,9 @@ extern "C" {

typedef int DistType; /* must be signed!! */

- inline double max(double x, double y) { - if (x >= y) - return x; - else - return y; - } inline double min(double x, double y) { - if (x <= y) - return x; - else - return y; - } - - inline int max(int x, int y) { - if (x >= y) - return x; - else - return y; - } - - inline int min(int x, int y) { - if (x <= y) - return x; - else - return y; - } +# include <algorithm> + using std::max; + using std::min;

struct Point { double x;


Owner: erg
Status: Fixed (15 Feb 2011)