Bug 116144 - Invalid array size value assigned with dependent name in parameter of template function cannot be detected by g++
Summary: Invalid array size value assigned with dependent name in parameter of templat...
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 13.2.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks: 24666
  Show dependency treegraph
 
Reported: 2024-07-30 14:25 UTC by C chen
Modified: 2024-07-31 04:33 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description C chen 2024-07-30 14:25:46 UTC
Consider the following code:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

template<typename T> void f(int a[(int)T()]);
void g() { f<char[10]>(0); }

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

There should be something wrong with "f<char[10]>" because the template argument passed to "f"  is an array value and cannot be 
value-initialized, for instance, in the form of "char[10]()".

Both EDG and clang reject the code, but gcc accepts it. This will only happen when the index value is related to a dependent name.

https://godbolt.org/z/GG4W5G755