[llvm-bugs] [Bug 47495] New: Wsizeof-array-div false positive when divisor is sizeof reference type
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Sep 11 07:50:30 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=47495
Bug ID: 47495
Summary: Wsizeof-array-div false positive when divisor is
sizeof reference type
Product: clang
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: sir.venceslas at gmail.com
CC: blitzrakete at gmail.com, dgregor at apple.com,
erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
richard-llvm at metafoo.co.uk
Hi,
I found a bug where clang reports a false positive here:
int my_function()
{
int array[10];
const int narray = sizeof(array)/sizeof(int&);
return narray;
}
clang output:
<stdin>:4:37: warning: expression does not compute the number of elements in
this array; element type is 'int', not 'int &' [-Wsizeof-array-div]
const int narray = sizeof(array)/sizeof(int&);
~~~~~ ^
<stdin>:3:9: note: array 'array' declared here
int array[10];
^
<stdin>:4:37: note: place parentheses around the 'sizeof(int &)' expression to
silence this warning
const int narray = sizeof(array)/sizeof(int&);
^
1 warning generated.
The standard says this about sizeof: "When applied to a reference or a
reference type, the result is the size of the referenced type."
I'm getting this even on the trunk version on godbolt.com
(https://godbolt.org/z/Pb4adf).
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200911/246c42fc/attachment.html>
More information about the llvm-bugs
mailing list