@@ -412,7 +412,16 @@ impl Loc for CppCode {
412412 | StatementIdentifier => {
413413 stats. logical_lines += 1 ;
414414 }
415-
415+ Declaration => {
416+ if count_specific_ancestors ! (
417+ node,
418+ WhileStatement | ForStatement | IfStatement ,
419+ CompoundStatement
420+ ) == 0
421+ {
422+ stats. logical_lines += 1 ;
423+ }
424+ }
416425 _ => {
417426 check_comment_ends_on_code_line ( stats, start) ;
418427 stats. lines . insert ( start) ;
@@ -880,6 +889,60 @@ mod tests {
880889 ) ;
881890 }
882891
892+ #[ test]
893+ fn cpp_lloc ( ) {
894+ check_metrics ! (
895+ "nsTArray<xpcGCCallback> callbacks(extraGCCallbacks.Clone());
896+ for (uint32_t i = 0; i < callbacks.Length(); ++i) {
897+ callbacks[i](status);
898+ }" ,
899+ "foo.cpp" ,
900+ CppParser ,
901+ loc,
902+ [ ( lloc, 3 , usize ) ] // nsTArray, for, callbacks
903+ ) ;
904+ }
905+
906+ #[ test]
907+ fn cpp_return_lloc ( ) {
908+ check_metrics ! (
909+ "uint8_t* pixel_data = frame.GetFrameDataAtPos(DesktopVector(x, y));
910+ return RgbaColor(pixel_data) == blank_pixel_;" ,
911+ "foo.cpp" ,
912+ CppParser ,
913+ loc,
914+ [ ( lloc, 2 , usize ) ] // pixel_data, return
915+ ) ;
916+ }
917+
918+ #[ test]
919+ fn cpp_for_lloc ( ) {
920+ check_metrics ! (
921+ "for (; start != end; ++start) {
922+ const unsigned char idx = *start;
923+ if (idx > 127 || !kValidTokenMap[idx]) return false;
924+ }" ,
925+ "foo.cpp" ,
926+ CppParser ,
927+ loc,
928+ [ ( lloc, 4 , usize ) ] // for, idx, if, return
929+ ) ;
930+ }
931+
932+ #[ test]
933+ fn cpp_while_lloc ( ) {
934+ check_metrics ! (
935+ "while (sHeapAtoms) {
936+ HttpHeapAtom* next = sHeapAtoms->next;
937+ free(sHeapAtoms);
938+ }" ,
939+ "foo.cpp" ,
940+ CppParser ,
941+ loc,
942+ [ ( lloc, 3 , usize ) ] // while, next, free,
943+ ) ;
944+ }
945+
883946 #[ test]
884947 fn python_string_on_new_line ( ) {
885948 // More lines of the same instruction were counted as blank lines
0 commit comments