D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6639 - Difference beetwen "foo" and "foo"c
Summary: Difference beetwen "foo" and "foo"c
Status: RESOLVED DUPLICATE of issue 2367
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: x86 Windows
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-10 05:37 UTC by zeljkog
Modified: 2011-09-10 08:36 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description zeljkog 2011-09-10 05:37:57 UTC
After thinking a bit more I have concluded its important consistency issue. So I reposted it as separate issue.

import std.stdio;

void f(S)(S str){
	writeln(str);
}

alias f!(string) fc;
alias f!(wstring) fc;

void main(){
	fc("foo");      // L11

//~ 	fc("foo"c);	 // works
//~ 	auto s = "foo";
//~ 	fc(s);       // works
}

//~ Compilation (dmd 2.055) breaks with message:

//~ bug.d(11): Error: function alias bug.f called with argument types:
//~ 	((string))
//~ matches both:
//~ 	bug.f!(string).f(string str)
//~ and:
//~ 	bug.f!(immutable(wchar)[]).f(immutable(wchar)[] str)

Maybe lexer should annotate string literal without StringPostfix according source code format?
Comment 1 yebblies 2011-09-10 06:42:26 UTC
It should work the same for function calls as it does for type deduction: an untyped string literal should default to immutable(char)[].

Fortunately there's already a patch for this.

*** This issue has been marked as a duplicate of issue 2367 ***
Comment 2 zeljkog 2011-09-10 08:12:58 UTC
Sorry for  duplication.

My point is maybe we don’t need unannotated string literal out of lexer.
Maybe c is better default, but we need simple rule.

Confess I’m not aware of all consequences. 
Something to think about, maybe?
Comment 3 yebblies 2011-09-10 08:36:14 UTC
(In reply to comment #2)
> My point is maybe we don’t need unannotated string literal out of lexer.
> Maybe c is better default, but we need simple rule.
> 
> Confess I’m not aware of all consequences. 
> Something to think about, maybe?

We actually do need it to be initially untyped.  If every string literal was implicitly utf-8, the following functions could not be called with a literal:
void fun(wstring s);
void fun(dstring s);
void fun(const(char)* s);

What is important is that a default type can be automatically used, and it already works this way some of the time.
auto x = "blah blah"; // x is typed as string

Extending this default type to function calls seems natural to me.