[Bug c++/54813] New: NULL pointer conversion fails for template code

2012-10-04 Thread tjablin at gmail dot com

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

 Bug #: 54813
   Summary: NULL pointer conversion fails for template code
Classification: Unclassified
   Product: gcc
   Version: 4.6.3
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
AssignedTo: unassig...@gcc.gnu.org
ReportedBy: tjab...@gmail.com


int foo(int i);

template static void bar(Fun fun, char[][sizeof(fun(0))]) {}

void baz() {

  // With an explicit template parameter, 0 is converted to a multidimensional
  // array
  bar(foo, 0); // succeeds

  // The template type is inferred when a has the right type.
  char a[4][sizeof(foo(0))];
  bar(foo, a);   // succeeds

  // Combining the two previous examples fails in g++ but is accepted by
clang++.
  // Compilers that emit errors for this line: g++ 4.4.7, 4.5.3, 4.6.3
  // Compilers that will compile this line: clang++ 3.2
  bar(foo, 0);   // failure
}

Error message with g++ 4.6.3:
test.cc: In function ‘void baz()’:
test.cc:9:13: error: no matching function for call to ‘bar(int (&)(int), int)’
test.cc:9:13: note: candidate is:
test.cc:3:33: note: template void bar(Fun, char (*)[sizeof
(fun(0))])


[Bug c++/54813] NULL pointer conversion fails for template code

2012-10-04 Thread tjablin at gmail dot com


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



--- Comment #1 from tjablin at gmail dot com 2012-10-04 16:41:06 UTC ---

I have further simplified the testcase as follows:



template static void bar(T, char[][sizeof(T)]) {}



void baz() {

  bar(0, 0); // succeeds

  char a[4][sizeof(int)];

  bar(0, a);  // succeeds

  bar(0, 0);  // fails

}