Fix to following warning by introducing a temporary variable:
include/linux/cred.h: In function 'get_cred':
include/linux/cred.h:187: warning: passing argument 1 of
'get_new_cred' discards qualifiers from pointer target type
Signed-off-by: Hannes Eder <[email protected]>
---
With -O2 the same code as for the original function is generated.
include/linux/cred.h | 3 ++-
1 files changed, 2 insertions(+), 1 deletions(-)
diff --git a/include/linux/cred.h b/include/linux/cred.h
index 26c1ab1..2ab8cf7 100644
--- a/include/linux/cred.h
+++ b/include/linux/cred.h
@@ -184,7 +184,8 @@ static inline struct cred *get_new_cred(struct cred *cred)
*/
static inline const struct cred *get_cred(const struct cred *cred)
{
- return get_new_cred((struct cred *) cred);
+ struct cred *non_const_cred = (struct cred *) cred;
+ return get_new_cred(non_const_cred);
}
/**
Hannes Eder <[email protected]> wrote:
> Fix to following warning by introducing a temporary variable:
>
> include/linux/cred.h: In function 'get_cred':
> include/linux/cred.h:187: warning: passing argument 1 of
> 'get_new_cred' discards qualifiers from pointer target type
Interesting. I believe that's a compiler bug. Explicitly casting away the
const should avoid this warning.
David
On Thu, Nov 20, 2008 at 11:19 PM, David Howells <[email protected]> wrote:
> Hannes Eder <[email protected]> wrote:
>
>> Fix to following warning by introducing a temporary variable:
>>
>> include/linux/cred.h: In function 'get_cred':
>> include/linux/cred.h:187: warning: passing argument 1 of
>> 'get_new_cred' discards qualifiers from pointer target type
>
> Interesting. I believe that's a compiler bug. Explicitly casting away the
> const should avoid this warning.
Strange. I think you are right, looks like a compiler bug. I am using
gcc (GCC) 4.2.4 (Ubuntu 4.2.4-1ubuntu3). Compiling the following code
snippet does not yield a spurious warning:
struct foo {
int a;
};
static inline struct foo *bar(struct foo *foo)
{
foo->a++;
return foo;
}
static inline const struct foo *bar2(const struct foo *foo)
{
return bar((struct foo*)foo);
}
What do you suggest, report this as a gcc bug?
-Hannes
Hannes Eder <[email protected]> wrote:
> What do you suggest, report this as a gcc bug?
You could do. It might be worth checking to see if it's fixed with a newer
gcc first, though.
David
On Fri, Nov 21, 2008 at 5:25 PM, David Howells <[email protected]> wrote:
> Hannes Eder <[email protected]> wrote:
>
>> What do you suggest, report this as a gcc bug?
>
> You could do. It might be worth checking to see if it's fixed with a newer
> gcc first, though.
The spurious warning is gone with gcc (Ubuntu 4.3.2-1ubuntu11) 4.3.2.
Hannes
Hannes Eder <[email protected]> wrote:
> The spurious warning is gone with gcc (Ubuntu 4.3.2-1ubuntu11) 4.3.2.
Then I wouldn't worry about it too much.
David