Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(2076)

Issue 4698047: [PATCH] Begin to implement the C++0x narrowing error (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
12 years, 9 months ago by Jeffrey Yasskin
Modified:
12 years, 8 months ago
CC:
cymbal-team_google.com
Base URL:
https://llvm.org/svn/llvm-project/cfe/trunk/
Visibility:
Public.

Description

This patch implements as much of the narrowing conversion error specified by [dcl.init.list] as is possible without generalized initializer lists or full constant expression support, and emits a c++0x-compat warning in C++98 mode. I haven't done much with this code before, so let me know if there are better ways to do pieces of this, or if I've attached the logic in completely the wrong place. The FixIt currently uses a typedef's basename without qualification, which is likely to be incorrect on some code. I'm not sure I'll need anything more correct to clean up Google's codebase, but if you want me to fix it up I'd like to do that in a separate change. The "has the same value after a round-trip through another type" logic is messier than I'd like, but cleaning it up appears to need more methods on types like APInt and APFloat, which I'd like to postpone until another change too. If I'm just missing existing facilities, please point them out. The warning is currently off by default. I'll fix LLVM and clang before turning it on.

Patch Set 1 #

Patch Set 2 : Fix the tests #

Patch Set 3 : Refactor #

Patch Set 4 : Use new APFloat API #

Patch Set 5 : Use the DiagnosticBuilder<<APValue operator from issue 4749047 #

Patch Set 6 : Sync #

Patch Set 7 : Split out c++0x-compat warning and fix TypedefTypes #

Patch Set 8 : Sync #

Total comments: 8

Patch Set 9 : Fix Sean's review comments. #

Patch Set 10 : Sync #

Unified diffs Side-by-side diffs Delta from patch set Stats (+436 lines, -8 lines) Patch
M include/clang/Basic/DiagnosticGroups.td View 1 2 3 4 5 6 7 1 chunk +2 lines, -1 line 0 comments Download
M include/clang/Basic/DiagnosticSemaKinds.td View 1 2 3 4 5 6 7 8 9 1 chunk +15 lines, -0 lines 0 comments Download
M include/clang/Sema/Initialization.h View 1 2 3 4 5 6 7 1 chunk +12 lines, -1 line 0 comments Download
M include/clang/Sema/Sema.h View 1 2 3 4 5 6 7 8 9 1 chunk +2 lines, -1 line 0 comments Download
M lib/Sema/SemaInit.cpp View 1 2 3 4 5 6 7 8 9 9 chunks +216 lines, -5 lines 0 comments Download
A test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp View 1 2 3 4 5 6 7 8 1 chunk +156 lines, -0 lines 0 comments Download
A test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x-fixits.cpp View 1 2 3 4 5 6 7 8 1 chunk +33 lines, -0 lines 0 comments Download

Messages

Total messages: 5
Jeffrey Yasskin
Diff at http://codereview.appspot.com/download/issue4698047_7001.diff, but the up to date version will always be at http://codereview.appspot.com/4698047.
12 years, 9 months ago (2011-07-14 04:23:24 UTC) #1
Jeffrey Yasskin (google)
I've attached the latest version of this patch. On Wed, Jul 13, 2011 at 9:23 ...
12 years, 9 months ago (2011-07-18 16:55:21 UTC) #2
scshunt
Looks good, mostly. A few comments. http://codereview.appspot.com/4698047/diff/30001/include/clang/Basic/DiagnosticSemaKinds.td File include/clang/Basic/DiagnosticSemaKinds.td (right): http://codereview.appspot.com/4698047/diff/30001/include/clang/Basic/DiagnosticSemaKinds.td#newcode2472 include/clang/Basic/DiagnosticSemaKinds.td:2472: "override this error ...
12 years, 9 months ago (2011-07-21 23:46:34 UTC) #3
scshunt
Looks pretty good; a few comments and then I'd say it's ready to go.
12 years, 9 months ago (2011-07-22 00:03:08 UTC) #4
Jeffrey Yasskin
12 years, 9 months ago (2011-07-22 19:43:23 UTC) #5
http://codereview.appspot.com/4698047/diff/30001/include/clang/Basic/Diagnost...
File include/clang/Basic/DiagnosticSemaKinds.td (right):

http://codereview.appspot.com/4698047/diff/30001/include/clang/Basic/Diagnost...
include/clang/Basic/DiagnosticSemaKinds.td:2472: "override this error by
inserting an explicit cast">;
On 2011/07/21 23:46:35, scshunt wrote:
> s/error/message/ for when it's a warning?

Done.

http://codereview.appspot.com/4698047/diff/30001/lib/Sema/SemaInit.cpp
File lib/Sema/SemaInit.cpp (right):

http://codereview.appspot.com/4698047/diff/30001/lib/Sema/SemaInit.cpp#newcod...
lib/Sema/SemaInit.cpp:5163: OS << BT->getName(S.getLangOptions());
On 2011/07/21 23:46:35, scshunt wrote:
> Are template parameters TypedefTypes? An assert here that one of the branches
> was taken would be nice.

Template parameters wind up substituted here, so you get a cast to the
underlying type, not the symbolic type. But clang records the original type
parameter's spelling, so I've added a branch to catch that, and a branch to just
return in case we the target type wasn't a builtin for some reason.

... Or not. That breaks fixits for MyTpl<char>, where the char member also has a
substituted template type, and there's no easy way to tell at which level the
type was substituted.

Everything that can be narrowed to shows up as a BuiltinType anyway, but I've
left the else just in case.

http://codereview.appspot.com/4698047/diff/30001/test/CXX/dcl.decl/dcl.init/d...
File test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp (right):

http://codereview.appspot.com/4698047/diff/30001/test/CXX/dcl.decl/dcl.init/d...
test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp:4: // mode.
On 2011/07/21 23:46:35, scshunt wrote:
> I don't see any tests for the fixit anywhere; those would be useful.

I've added p7-0x-fixits.cpp, and that discovered that my new
SubstTemplateTypeParmType branch was breaking the fixits for initializations of
templates. :(

http://codereview.appspot.com/4698047/diff/30001/test/CXX/dcl.decl/dcl.init/d...
test/CXX/dcl.decl/dcl.init/dcl.init.list/p7-0x.cpp:36: // * from a
floating-point type to an integer type, or
On 2011/07/21 23:46:35, scshunt wrote:
> Testing for non-constant floats would probably be good.

The code doesn't check whether floats in float->int conversions are constant or
non-constant. But ok.
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b