The following code breaks \pgfmath@@declarefunction.
\pgfmathdeclarefunction{func}{1}{%
\checkarg{#1}
\ifchecked
\def\pgfmathresult{1}%
\else
\def\pgfmathresult{0}%
\fi
}
\newif\ifchecked
\def\checkarg#1{%
\ifdim#1pt>0pt
\checkedtrue
\else
\checkedfalse
\fi
}
TeX reports
! Too many }'s.
\pgfmath@@declarefunction ...def #1{#2}\def #2{#4}
\or \def #1##1{\pgfmathpar...
The reason is that when func is declared, \ifchecked has not yet been defined. Tex does not see it as a conditional and interprets the \fi statement in the body of func as closing the \ifcase conditional in \pgfmath@@declarefunction.
The solution is to defer the definition of the function after \ifcase ... \fi.
Sorry, this should be a bug report. It ended up in the wrong category and sourceforge does not allow me to move or modify the ticket.
Fixed in https://sourceforge.net/p/pgf/git/ci/fd9258d8273d46387438ae9ad442e8d24dcd0e71/
The MWE could have been much shorter: