[cfe-dev] bug with USRs and fixed-length arrays?

James Dennett james.dennett at gmail.com
Fri Nov 2 12:11:45 PDT 2012

On Fri, Nov 2, 2012 at 11:49 AM, Iestyn Bleasdale-Shepherd <
iestyn at valvesoftware.com> wrote:

> Hi Dmitri - thanks for the response!
> The line you quote ends with "...where the type qualifiers (if any) are
> those specified within the [ and ] of the array type derivation."
> This qualification allows disambiguation between my two example functions
> - as it must, since they may have completely different implementations and
> may be passed as different function pointers.
According to the rules of C++, the two declarations
  void Func(char array[32]);
  void Func(char array[16]);
declare the same function, which has one parameter of type char*.  They
declare the same function as
  void Func(char *array);

It is an error to define both of them -- the following should generate a
diagnostic from any conforming C++ compiler:
  void Func(char array[32]) {}
  void Func(char array[16]) {}

And it does so with Clang:

/tmp/redecl.cc:2:6: error: redefinition of 'Func'
void Func(char array[16]) {}
/tmp/redecl.cc:1:6: note: previous definition is here
void Func(char array[32]) {}
1 error generated.

(It's true that arrays are not pointers, and pointers are not arrays, but
in the special case of function declarations there is no way to pass an
array by value, and the only way to constrain the size of a passed array is
to pass a pointer or reference to a particular size of array.)

> Am I missing something here? We use these kinds of overloads in our code,
> in cases which depend on their resolving to *different* functions.

That's not possible in C++.  Maybe you can show your actual code?

-- James
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20121102/a93bb224/attachment.html>

More information about the cfe-dev mailing list