This question is from the comments at the foot of Abbreviations for AM, PM (small caps) for use within \textbf. Readers will get the remaining gist from there.
With
\newcommand\cmd[2][0]{\def\y{#1}}
\edef\x{\cmd{1}}
I get
{\edef}
\cmd ->\@protected@testopt \cmd \\cmd {0}
\@protected@testopt #1->\ifx \protect \@typeset@protect \expandafter \@testopt
\else \@x@protect #1\fi
#1<-\cmd
{\ifx}
{true}
{\expandafter}
{\else}
\@testopt #1#2->\kernel@ifnextchar [{#1}{#1[{#2}]}
#1<-\\cmd
#2<-0
\kernel@ifnextchar #1#2#3->\let \reserved@d =#1\def \reserved@a {#2}\def \reser
ved@b {#3}\futurelet \@let@token \@ifnch
#1<-[
#2<-\\cmd
#3<-\\cmd [{0}]
\reserved@a #11#2{->\expandafter \def \expandafter \\cmd \reserved@b #11{
! Argument of \reserved@a has an extra }.
<inserted text>
\par
<to be read again>
}
l.3103 \edef\x{\cmd{1}}
? x
Is that robustness? See also Is there a robust \renewcommand replacement?.
\DeclareRobustCommand
which has the same parameter syntax as\newcommand
. – bodo Jun 19 '12 at 7:35