Handle l-value refs correctly

Reviewed By: jvillard

Differential Revision: D3757766

fbshipit-source-id: 12edcfc
master
Ryan Rhee 8 years ago committed by Facebook Github Bot 9
parent 36b0a957bd
commit e19550a43b

@ -77,11 +77,16 @@ let mutable_local_vars_advice context decl =
let open CFrontend_utils.Ast_utils in
match decl with
| Clang_ast_t.VarDecl(decl_info, _, qual_type, _) ->
let is_const_ref = match Ast_utils.get_type qual_type.qt_type_ptr with
| Some LValueReferenceType (_, {Clang_ast_t.qt_is_const}) ->
qt_is_const
| _ -> false in
let is_const = qual_type.qt_is_const || is_const_ref in
let condition = context.CLintersContext.is_ck_translation_unit
&& is_in_main_file decl
&& (is_objc () || is_objcpp ())
&& (not (is_syntactically_global_var decl))
&& (not qual_type.qt_is_const) in
&& (not is_const) in
if condition then
Some {
CIssue.issue = CIssue.Mutable_local_variable_in_component_file;

@ -92,3 +92,17 @@ typedef struct { int thisStructIsEmpty; } CKSize;
size:{}]];
}
@end
typedef struct { int a; } BarStruct;
@interface BarComponent : CKCompositeComponent
@end
@implementation BarComponent
+ (instancetype) new {
// C++ structs
BarStruct s1; // error
const BarStruct& s2 = s1; // no error
BarStruct& s3 = s1; // error
const BarStruct s4 = {.a = 3}; // no error
}
@end

@ -10,7 +10,7 @@
package endtoend.objcpp.componentkit;
import static org.hamcrest.MatcherAssert.assertThat;
import static utils.matchers.ResultContainsLineNumbers.containsLines;
import static utils.matchers.ResultContainsLineNumbers.containsOnlyLines;
import static utils.matchers.ResultContainsErrorInMethod.contains;
import com.google.common.collect.ImmutableList;
@ -51,7 +51,7 @@ public class MutableLocalVariableTest {
assertThat(
"Results should contain " + MUTABLE_LOCAL_VARIABLE_IN_COMPONENT_FILE,
inferResults,
containsLines(new int[]{58, 69, 74, 76, 80, 85}));
containsOnlyLines(new int[]{58, 69, 74, 76, 80, 85, 103, 105}));
}
@Test

Loading…
Cancel
Save