[LLVMbugs] [Bug 13110] New: Should warn for "const" applied to reference type (even a typedef)
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Wed Jun 13 18:39:32 PDT 2012
http://llvm.org/bugs/show_bug.cgi?id=13110
Bug #: 13110
Summary: Should warn for "const" applied to reference type
(even a typedef)
Product: clang
Version: trunk
Platform: All
OS/Version: All
Status: NEW
Severity: enhancement
Priority: P
Component: C++
AssignedTo: unassignedclangbugs at nondot.org
ReportedBy: arthur.j.odwyer at gmail.com
CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
Classification: Unclassified
cat >test.cc <<EOF
typedef int& IntRef;
void foo(const IntRef m);
void bar(int& const m);
EOF
clang++ -W -Wall -Wextra -c test.cc
test.cc:3:15: error: 'const' qualifier may not be applied to a reference
void bar(int& const m);
^
1 error generated.
I see why it's useful to have the qualifier on "const T" be silently ignored
when T is a template type parameter, but wouldn't it be helpful and non-hurtful
for Clang to give a non-fatal warning message in the above case, where T is
merely a typedef?
A quick Google search will turn up more than a handful of frequently asked
questions from C++ newbies asking why "const IntRef" doesn't mean the same
thing as "const int &". And then when they hear the answer ("reference types
can't be const-qualified"), they'll usually follow up with "whoa, why does the
compiler allow me to type that at all, then?" And then the thread dies because
there's really no good answer to that.
Could Clang be the first compiler to diagnose this common newbie mistake with a
warning message?
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the llvm-bugs
mailing list