[LLVMbugs] [Bug 11546] New: Recursive template flagged when defined out of line

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Mon Dec 12 14:04:33 PST 2011


http://llvm.org/bugs/show_bug.cgi?id=11546

             Bug #: 11546
           Summary: Recursive template flagged when defined out of line
           Product: clang
           Version: trunk
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
        AssignedTo: unassignedclangbugs at nondot.org
        ReportedBy: ivan at ootbcomp.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified


Found in clang 3.1, w & wo c++11 enabled:
s3:~/ootbc/common$ clang -v
clang version 3.1 (trunk 145795)
Target: x86_64-unknown-linux-gnu
Thread model: posix


This code:

template<int v>
class       bitWidthHolding {
public:
    /** width is the number of bits occupied by the template parameter v
            */
    static const
    int    w1;
    static const
    int    w2 = (v == 0 ? 0 : bitWidthHolding<(v >> 1)>::w2 + 1);
    };

template<int v>
const
int    bitWidthHolding<v>::w1 =
            (v == 0 ? 0 : bitWidthHolding<(v >> 1)>::w1 + 1);

int main() {
    int v1 = bitWidthHolding<3>::w1;
    int v2 = bitWidthHolding<3>::w2;
    return 0;
    }


gets you this:

s3:~/ootbc1/common$ clang++ -std=c++11 foo.cc
foo.cc:15:18: warning: variable 'w1' is uninitialized when used within its own
      initialization [-Wuninitialized]
                        (v == 0 ? 0 : bitWidthHolding<(v >> 1)>::w1 + 1);
                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foo.cc:15:45: note: in instantiation of static data member
      'bitWidthHolding<0>::w1' requested here
                        (v == 0 ? 0 : bitWidthHolding<(v >> 1)>::w1 + 1);
                                                                 ^
foo.cc:15:45: note: in instantiation of static data member
      'bitWidthHolding<1>::w1' requested here
                        (v == 0 ? 0 : bitWidthHolding<(v >> 1)>::w1 + 1);
                                                                 ^
foo.cc:18:31: note: in instantiation of static data member
      'bitWidthHolding<3>::w1' requested here
        int v1 = bitWidthHolding<3>::w1;
                                     ^
1 warning generated.

Note that no warning is issued when w2 is defined inside the class, but is
issued when w1 is defined outside; w1 and w2 are otherwise identical. No
warning is justified in either case, because the nested invocation has a
different template argument except for the zero argument case, for which the
recursive invocation should not be evaluated by ?:. However, right or wrong it
should not matter where the definition is.

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list