Otherwise it doesn't work very well in figure captions and suchlike.
% We're meant to typeset a reference. The first job is to see whether
% there's an optional argument. If so, grab it; otherwise |\relax| will do.
% \begin{macrocode}
-\def\xref{\@ifnextchar[\xref@{\xref@[\relax]}}
+\DeclareRobustCommand\xref{\@ifnextchar[\xref@{\xref@[\relax]}}
\def\xref@[#1]#2{\xref@@{#1}#2:\q@delim:\q@delim:\q@delim\q@delim}
% \end{macrocode}
% Right; now we abuse \TeX's argument parser to pick apart the reference