Dear clang developers,

I was investigating whether our computer simulation library
LibGeoDecomp would work with clang++, when I noticed that some of the
unit tests were failing. Apparently clang++ handles partial
specialization of member function templates in combination with
inheritance differently from other compilers (e.g. g++ and icpc).

I've tried to come up with a minimal test program which reproduces the
odd behavior (attached). Having been pruned so much, the program
itself doesn't make much sense. It was originally part of our code
which handles boundary conditions. IMHO the program should yield the
output "function2" twice, but with clang++ I get "function5" for the
first invocation. Is this a bug in clang++, or is this simply
undefined behavior?

Reproduction:
-------------

icpc test3.cpp -o test && ./test && echo "-------------------------" &&  g++ 
test3.cpp -o test && ./test && echo "------------" && clang++ test3.cpp -o test 
&& ./test

Output:
-------

function2
function2
-------------------------
function2
function2
------------
function5
function2

Thanks!
-Andreas


-- 
==========================================================
Andreas Schäfer
HPC and Grid Computing
Chair of Computer Science 3
Friedrich-Alexander-Universität Erlangen-Nürnberg, Germany
+49 9131 85-27910
PGP/GPG key via keyserver
http://www.libgeodecomp.org
==========================================================

(\___/)
(+'.'+)
(")_(")
This is Bunny. Copy and paste Bunny into your
signature to help him gain world domination!
#include <iostream>

template<int X=0, int Y=0, int Z=0>
class FixedCoord
{};

template<typename CELL, bool FLAG>
class MyWest
{
public:
    void access(MyWest) const
    {
        std::cout << "function1\n";
    }
};

template<typename CELL>
class MyWest<CELL, true>
{
public:
    const CELL access(FixedCoord<-1, -1,  0>, const CELL **lines) const
    {
        std::cout << "function2\n";
        return 2;
    }
};

template<typename CELL, bool FLAG>
class MyTop
{
public:
    void access(MyTop) const
    {
        std::cout << "function3\n";
    }
};

template<typename CELL>
class MyTop<CELL, true>
{
public:
    template<int X>
    const CELL access(FixedCoord< X, -1,  0>, const CELL **lines) const
    {
        std::cout << "function4\n";
        return 4;
    }
};

template<typename CELL, bool BOUNDARY_WEST, bool BOUNDARY_TOP>
class MyLinePointerNeighborhood :
    public MyWest<  CELL, BOUNDARY_WEST>,
    public MyTop<   CELL, BOUNDARY_TOP>
{
public:
    using MyWest<  CELL, BOUNDARY_WEST  >::access;
    using MyTop<   CELL, BOUNDARY_TOP   >::access;

    MyLinePointerNeighborhood(const CELL **lines) :
        lines(lines)
    {}

    template<int X, int Y, int Z>
    const CELL access(FixedCoord<X, Y, Z>, const CELL **lines) const
    {
        std::cout << "function5\n";
        return 5;
    }

    template<int X, int Y, int Z>
    const CELL operator[](FixedCoord<X, Y, Z>) const
    {
        return access(FixedCoord<X, Y, Z>(), lines);
    }

private:
    const CELL **lines;
};

int main(int argc, char **argv)
{
    int foo = -1;

    const int *pointers[] = {
        &foo
    };

    MyLinePointerNeighborhood<int, true, false> hood(pointers);
    hood[FixedCoord<-1, -1>()];
    hood.access(FixedCoord<-1, -1>(), pointers);

    return 0;
}

Attachment: signature.asc
Description: Digital signature

_______________________________________________
cfe-users mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-users

Reply via email to