return fmtprint(f, "(%N{ %,H })", n->right, n->list);
case OPTRLIT:
- if(fmtmode == FExp && n->left->implicit)
+ if(fmtmode == FExp) // handle printing of '&' below.
return fmtprint(f, "%N", n->left);
return fmtprint(f, "&%N", n->left);
if(fmtmode == FExp) { // requires special handling of field names
if(n->implicit)
fmtstrcpy(f, "{");
+ else if(n->right->implicit)
+ fmtprint(f, "&%T{", n->type);
else
fmtprint(f, "(%T{", n->type);
for(l=n->list; l; l=l->next) {
else
fmtstrcpy(f, " ");
}
- if(!n->implicit)
+ if(!n->implicit && !n->right->implicit)
return fmtstrcpy(f, "})");
return fmtstrcpy(f, "}");
}
return fmtprint(f, "%T literal", n->type);
if(fmtmode == FExp && n->implicit)
return fmtprint(f, "{ %,H }", n->list);
+ if(fmtmode == FExp && n->right->implicit)
+ return fmtprint(f, "&%T{ %,H }", n->type, n->list);
return fmtprint(f, "(%T{ %,H })", n->type, n->list);
case OKEY:
yyerror("invalid pointer type %T for composite literal (use &%T instead)", t, t->type);
goto error;
}
-
// Also, the underlying type must be a struct, map, slice, or array.
if(!iscomptype(t)) {
yyerror("invalid pointer type %T for composite literal", t);
goto error;
}
- t = t->type;
+ t = t->type;
}
switch(t->etype) {
if(t->bound < 0)
n->right = nodintconst(len);
n->op = OARRAYLIT;
+ // restore implicitness.
+ if(isptr[n->type->etype])
+ n->right->implicit = 1;
break;
case TMAP:
--- /dev/null
+package a
+
+import (
+ "unsafe"
+)
+
+type Collection struct {
+ root unsafe.Pointer
+}
+
+type nodeLoc struct{}
+
+type slice []int
+
+type maptype map[int]int
+
+func MakePrivateCollection() *Collection {
+ return &Collection{
+ root: unsafe.Pointer(&nodeLoc{}),
+ }
+}
+
+func MakePrivateCollection2() *Collection {
+ return &Collection{
+ root: unsafe.Pointer(&slice{}),
+ }
+}
+func MakePrivateCollection3() *Collection {
+ return &Collection{
+ root: unsafe.Pointer(&maptype{}),
+ }
+}
+
--- /dev/null
+// compiledir
+
+// Copyright 2013 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+// Issue 4879: export data misses the '&' for some
+// composite literals in inlined bodies.
+
+package ignored