[llvm-bugs] [Bug 38095] New: function attribute "diagnose_if" doesn't see const char *
via llvm-bugs
llvm-bugs at lists.llvm.org
Sun Jul 8 15:48:02 PDT 2018
https://bugs.llvm.org/show_bug.cgi?id=38095
Bug ID: 38095
Summary: function attribute "diagnose_if" doesn't see const
char *
Product: clang
Version: 6.0
Hardware: PC
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: Frontend
Assignee: unassignedclangbugs at nondot.org
Reporter: naruse at airemix.jp
CC: llvm-bugs at lists.llvm.org
Following code has two functions with "dignose_if" function attribute.
Their difference is just whose argument is `char *` or `const char *`.
But `const char *` one doesn't show error.
Is this intended behavior?
```
% clang --version
clang version 6.0.0 (tags/RELEASE_600/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
% cat b.c
int scan_args(char *fmt)
__attribute__((diagnose_if(fmt[0]!=2,"invalid format string","error")))
{
return 0;
}
int scan_args_const(const char *fmt)
__attribute__((diagnose_if(fmt[0]!=2,"invalid format string","error")))
{
return 0;
}
int
main(int argc, char **argv) {
return scan_args("20") + scan_args_const("20");
}
```
Expected behavior:
```
% clang b.c
b.c:15:26: error: invalid format string
return scan_args("20") + scan_args_const("20");
^
b.c:2:20: note: from 'diagnose_if' attribute on 'scan_args':
__attribute__((diagnose_if(fmt[0]!=2,"invalid format string","error")))
^ ~~~~~~~~~
b.c:15:50: error: invalid format string
return scan_args("20") + scan_args_const("20");
^
b.c:8:20: note: from 'diagnose_if' attribute on 'scan_args_const':
__attribute__((diagnose_if(fmt[0]!=2,"invalid format string","error")))
^ ~~~~~~~~~
2 errors generated.
```
Actual behavior:
```
% clang b.c
b.c:15:26: error: invalid format string
return scan_args("20") + scan_args_const("20");
^
b.c:2:20: note: from 'diagnose_if' attribute on 'scan_args':
__attribute__((diagnose_if(fmt[0]!=2,"invalid format string","error")))
^ ~~~~~~~~~
1 error generated.
```
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180708/09c42380/attachment.html>
More information about the llvm-bugs
mailing list