* Strange warnings from GCC++ 4.6.2 in Atmel Studio 6
@ 2012-12-17 14:25 George H. Barbehenn
2012-12-17 14:38 ` Florian Weimer
2012-12-17 15:17 ` Jonathan Wakely
0 siblings, 2 replies; 3+ messages in thread
From: George H. Barbehenn @ 2012-12-17 14:25 UTC (permalink / raw)
To: gcc-help
GCC:
I get the warning:
Warning 1 deprecated conversion from string constant to 'char*'
[-Wwrite-strings]
It is thrown on the following line:
myGLCD.print("* Universal Color TFT Display Library *", CENTER, 1);
There are two overloads of the print method:
void print(char *st, int x, int y, int deg=0);
void print(String st, int x, int y, int deg=0);
(folded code):
void UTFT::print(char *st, int x, int y, int deg)
{
}
void UTFT::print(String st, int x, int y, int deg)
{
}
I'm not sure why the compiler is confusing the overloads, is "String st"
somehow equivalent to "char *st"?
ghb
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Strange warnings from GCC++ 4.6.2 in Atmel Studio 6
2012-12-17 14:25 Strange warnings from GCC++ 4.6.2 in Atmel Studio 6 George H. Barbehenn
@ 2012-12-17 14:38 ` Florian Weimer
2012-12-17 15:17 ` Jonathan Wakely
1 sibling, 0 replies; 3+ messages in thread
From: Florian Weimer @ 2012-12-17 14:38 UTC (permalink / raw)
To: gbarbehenn; +Cc: gcc-help
On 12/17/2012 03:25 PM, George H. Barbehenn wrote:
> I'm not sure why the compiler is confusing the overloads, is "String st"
> somehow equivalent to "char *st"?
This depends on your environment, GCC doesn't provide a String type.
I suspect that GCC and the C++03 standard resolve the call to the char *
variant of the method, and do not take a constructor String(const char
*) into account, even if it existed.
--
Florian Weimer / Red Hat Product Security Team
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Strange warnings from GCC++ 4.6.2 in Atmel Studio 6
2012-12-17 14:25 Strange warnings from GCC++ 4.6.2 in Atmel Studio 6 George H. Barbehenn
2012-12-17 14:38 ` Florian Weimer
@ 2012-12-17 15:17 ` Jonathan Wakely
1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Wakely @ 2012-12-17 15:17 UTC (permalink / raw)
To: gbarbehenn; +Cc: gcc-help
On 17 December 2012 14:25, George H. Barbehenn wrote:
> GCC:
> I get the warning:
>
> Warning 1 deprecated conversion from string constant to 'char*'
> [-Wwrite-strings]
>
> It is thrown on the following line:
>
> myGLCD.print("* Universal Color TFT Display Library *", CENTER, 1);
>
> There are two overloads of the print method:
>
> void print(char *st, int x, int y, int deg=0);
> void print(String st, int x, int y, int deg=0);
>
> (folded code):
> void UTFT::print(char *st, int x, int y, int deg)
> {
> }
>
> void UTFT::print(String st, int x, int y, int deg)
> {
> }
>
> I'm not sure why the compiler is confusing the overloads, is "String st"
> somehow equivalent to "char *st"?
What makes you think it's confusing them? The warning doesn't say
anything like that.
"* Universal Color TFT Display Library *" is a string literal with
type const char*. In C++03 a string literal can be converted to a
char*, but that conversion is deprecated (and not allowed in C++11).
During overload resolution the compiler see that it can call the
print(char*,...) overload via the standard conversion from a string
literal to char*. Presumably calling the print(String, ...) overload
is either not possible or would require a user-defined conversion. A
standard conversion is always preferred to a user-defined conversion,
so the print(char*,...) overload is called, and the compiler warns you
that it used the deprecated conversion from string literal to char*.
If you want to force the other overload, either don't call it with a literal:
const char* s = "* Universal Color TFT Display Library *";
myGLCD.print(s, CENTER, 1);
or perform an explicit conversion:
myGLCD.print(String("* Universal Color TFT Display Library *"), CENTER, 1);
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-12-17 15:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-12-17 14:25 Strange warnings from GCC++ 4.6.2 in Atmel Studio 6 George H. Barbehenn
2012-12-17 14:38 ` Florian Weimer
2012-12-17 15:17 ` Jonathan Wakely
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).