[Bug c++/53763] New: Missing error check on decltype when used within variadic template argument list

o.mangold at googlemail dot com gcc-bugzilla@gcc.gnu.org
Sun Jun 24 16:24:00 GMT 2012


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53763

             Bug #: 53763
           Summary: Missing error check on decltype when used within
                    variadic template argument list
    Classification: Unclassified
           Product: gcc
           Version: 4.7.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: o.mangold@googlemail.com


In the example below, which is invalid code, no appropriate compiler error is
reported. The code is wrong, because "decltype(A::a(2))" is invalid as A is a
template class and would need template arguments. 

The compiler seams to silently skip the function call to B::b as if it was not
there (it produces only a message for the first call of b). The only thing that
is reported, though, is that y is used uninitialized. Apparently a later stage
knows that the function was not called.

It seems necessary that B takes a variadic template argument list for the
problem to appear, but I couldn't nail it down further.

--- compiler output ---
> g++ -Wall -std=c++11 example.c
example.c: In function ‘int main()’:
example.c:26:12: warning: ‘y’ is used uninitialized in this function
[-Wuninitialized]

--- example.cxx ---
#include<stdio.h>

template<typename TYPE>
struct A
{
  static int a(TYPE value)
  {
    return value;
  }
};

template<typename... ARGS>
struct B
{
  static int b(ARGS... args)
  {
    printf("hello world %i\n",args...);
    return 0;
  }
};

int main()
{
  int x = B<decltype(A<int>::a(1))>::b(A<int>::a(1));
  int y = B<decltype(A     ::a(2))>::b(A<int>::a(2));
  return x+y;
}



More information about the Gcc-bugs mailing list