Merge pull request #1492 from geoffw0/exprnoeffectweak

CPP: Fix for 'Expression has no effect' on calls to weak functions
This commit is contained in:
Jonas Jensen
2019-06-25 10:58:28 +02:00
committed by GitHub
4 changed files with 26 additions and 2 deletions

View File

@@ -33,3 +33,4 @@
| volatile.c:12:5:12:9 | access to array | This expression has no effect. | volatile.c:12:5:12:9 | access to array | |
| volatile.c:16:5:16:7 | * ... | This expression has no effect. | volatile.c:16:5:16:7 | * ... | |
| volatile.c:20:5:20:13 | * ... | This expression has no effect. | volatile.c:20:5:20:13 | * ... | |
| weak.c:18:2:18:18 | call to myNothingFunction | This expression has no effect (because $@ has no external side effects). | weak.c:2:5:2:21 | myNothingFunction | myNothingFunction |

View File

@@ -0,0 +1,20 @@
int myNothingFunction()
{
// does nothing
return 0;
}
int __attribute__((__weak__)) myWeakNothingFunction()
{
// does nothing, but we could be overridden at the linker stage with a non-weak definition
// from elsewhere in the program.
return 0;
}
void testWeak() {
myNothingFunction(); // BAD
myWeakNothingFunction(); // GOOD
}