https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103920

            Bug ID: 103920
           Summary: No warning for large structs passed by value ?
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dcb314 at hotmail dot com
  Target Milestone: ---

For the following code:

$ more jan5c.cc

struct S
{
        long a;
        long b;
        long c;
        long d;
        long a2;
        long b2;
        long c2;
        long d2;
};

void f1( const S s);
void f2( S s);

gcc has not a lot to say:

$ /home/dcb/gcc/results/bin/gcc -c -O2 -Wall -Wextra -pedantic jan5c.cc
$

cppcheck does a slightly better job:

$ /home/dcb/cppcheck/trunk.git/cppcheck --enable=all jan5c.cc
jan5c.cc:14:18: performance: Function parameter 's' should be passed by const
reference. [passedByValue]
void f1( const S s);
                 ^
Also, clang-13 doesn't say anything. 

Judgement call, but "large" might mean four words or more. 

Example code derived from code in the Linux kernel, so even kernel programmers
do this kind of thing in practice.

Reply via email to