diff --git a/infer/src/backend/prover.ml b/infer/src/backend/prover.ml index 9120a6e6c..7a8955704 100644 --- a/infer/src/backend/prover.ml +++ b/infer/src/backend/prover.ml @@ -1636,8 +1636,8 @@ let texp_imply tenv subs texp1 texp2 e1 calc_missing = | Sil.Sizeof (Sil.Tstruct _, _), Sil.Sizeof (Sil.Tstruct _, _) | Sil.Sizeof (Sil.Tarray _, _), Sil.Sizeof (Sil.Tarray _, _) | Sil.Sizeof (Sil.Tarray _, _), Sil.Sizeof (Sil.Tstruct _, _) - | Sil.Sizeof (Sil.Tstruct _, _), Sil.Sizeof (Sil.Tarray _, _) -> - !Config.curr_language = Config.Java + | Sil.Sizeof (Sil.Tstruct _, _), Sil.Sizeof (Sil.Tarray _, _) + when !Config.curr_language = Config.Java -> true | Sil.Sizeof (typ1, _), Sil.Sizeof (typ2, _) -> (Sil.is_cpp_class typ1 && Sil.is_cpp_class typ2) || diff --git a/infer/tests/codetoanalyze/cpp/errors/subtyping/dynamic_cast.cpp b/infer/tests/codetoanalyze/cpp/errors/subtyping/dynamic_cast.cpp index 9ccf3f16b..cae8d729c 100644 --- a/infer/tests/codetoanalyze/cpp/errors/subtyping/dynamic_cast.cpp +++ b/infer/tests/codetoanalyze/cpp/errors/subtyping/dynamic_cast.cpp @@ -33,7 +33,6 @@ int wrongCastOfArgumentPointer(){ return 1/castOfArgumentPointer(&pdd); } -//This should give a CLASS_CAST_EXCEPTION error but doesn't yet. int wrongCastOfArgumentReference(){ Base pdd; return castOfArgumentReference(pdd); diff --git a/infer/tests/endtoend/cpp/DynamicCastTest.java b/infer/tests/endtoend/cpp/DynamicCastTest.java index 27b7ccd08..7cd7b8965 100644 --- a/infer/tests/endtoend/cpp/DynamicCastTest.java +++ b/infer/tests/endtoend/cpp/DynamicCastTest.java @@ -107,4 +107,14 @@ public class DynamicCastTest { contains(CLASS_CAST_EXCEPTION, FILE, "wrongReferenceCastNotAssigned")); } + @Test + public void whenInferRunsOnWrongCastOfArgumentReferenceThenClassCastExceptionIsFound() + throws InterruptedException, IOException, InferException { + InferResults inferResults = InferRunner.runInferCPP(inferCmd); + assertThat( + "Results should contain class cast exception", + inferResults, + contains(CLASS_CAST_EXCEPTION, FILE, "wrongCastOfArgumentReference")); + } + }